In this tutorial, I’ll show you
how to create a login system in vb.net that will encrypt password character
into Microsoft Access Database. In various application today, data are very
important for security, and there’s a lot of application apply this kind of
encryption to ensure that all information specifically password by many users
not hack by any users. This simple idea of encryption in Visual Basic.Net will
give you an idea how to use it in your programming techniques. First thing you
need is to create a database name [DbAccount] and tblAccount that has a column
ID, Username, and Password.
To encrypt password character to
save into database:
Dim
sPlainText As String
= Me.txtPasswordSave.Text
If Not String.IsNullOrEmpty(sPlainText) Then
Dim memoryStream As MemoryStream = New
MemoryStream()
Dim cryptoStream As CryptoStream = New
CryptoStream(memoryStream, Me.encryptor, CryptoStreamMode.Write)
cryptoStream.Write(Me.enc.GetBytes(sPlainText),
0, sPlainText.Length)
cryptoStream.FlushFinalBlock()
Me.txtPasswordSave.Text = Convert.ToBase64String(memoryStream.ToArray())
Me.Validate()
Me.TblAccountBindingSource.EndEdit()
Me.TblAccountTableAdapter.Update(Me.DbAccountDataSet.tblAccount)
MessageBox.Show("Saved")
memoryStream.Close()
cryptoStream.Close()
Else
MessageBox.Show("Please
fill the textbox")
End If
To login my username and
password:
Dim sPlainText As String = Me.txtPasswordLogin.Text
If Not String.IsNullOrEmpty(sPlainText) Then
Dim memoryStream As MemoryStream = New
MemoryStream()
Dim cryptoStream As CryptoStream = New
CryptoStream(memoryStream, Me.encryptor, CryptoStreamMode.Write)
cryptoStream.Write(Me.enc.GetBytes(sPlainText),
0, sPlainText.Length)
cryptoStream.FlushFinalBlock()
Me.txtPasswordLogin.Text = Convert.ToBase64String(memoryStream.ToArray())
If Me.TblAccountTableAdapter.FillByLogin(Me.DbAccountDataSet.tblAccount, Me.txtPasswordLogin.Text, txtUsername.Text) Then
txtPasswordLogin.Clear()
MessageBox.Show("Matched")
Else
txtPasswordLogin.Clear()
MessageBox.Show("Not match")
End If
memoryStream.Close()
cryptoStream.Close()
Else
MessageBox.Show("Please
fill the textbox")
End If
Only password was encrypted into
database, in this login form I enter the exact name and encrypt it to match the
character that was already saved on my database.
The exact value of that password
was joannou, and once the encryption was made only decryption can retrieve to
display what the hash key word means.
Decryption will cover for my next
tutorial.
0 comments:
Post a Comment