KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an online SMF forum and when a user registers the password is encrypted with SHA1 in the database. I need to create a vb program with a login feature where only members of the forum can login. Now the part I'm stuck in is how do I encrypt the password into SHA1 in visual basic? I included some code which I don't know is correct or not so please help me out. Imports System.Security.Cryptography Public Class Form2 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' declare those variables Dim password As String Dim passwordSHA As String password = txtPassword.Text ' give password the value of the password textbox Call passwordEncryptSHA(password) ' Lets call the first password encryption function for SHA1 passwordSHA = passwordEncryptSHA(password) ' give the variable the returned SHA value ' finally we will display both values in the corresponding textboxes txtSHA1.Text = passwordSHA End Sub Public Function passwordEncryptSHA(ByVal password As String) As String Dim sha As New SHA1CryptoServiceProvider ' declare sha as a new SHA1CryptoServiceProvider Dim bytesToHash() As Byte ' and here is a byte variable bytesToHash = System.Text.Encoding.ASCII.GetBytes(password) ' covert the password into ASCII code bytesToHash = sha.ComputeHash(bytesToHash) ' this is where the magic starts and the encryption begins Dim encPassword As String = "" For Each b As Byte In bytesToHash encPassword += b.ToString("x2") Next Return encPassword ' boom there goes the encrypted password! End Function Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub End Class Thank you and please don't be mean because I am still learning (I'm 15)!
Tags (comma-separated)
Save Edits
Cancel