I currently have a MySQL database that stores, among other things, a users name and password for login. I have a MS Access 2010 front end with a login screen that I built that asks for the user password and name and compares it to the MySQL user name and password and if they match it will open another MS Access form. I would now like to store the passwords in hash sha1 in the MySQL database but I don’t know how to write my vbscript so that it will take the password that the user typed in at the MS Access form, convert it to hash sha1 and compare it to what is already in the MySQL database for that particular user. I’ve included the vbscript that I used when I wasn’t using hash. Any assitance would be greatly appreciated.
'compares username and password to a query and will either open another form OR display an incorrect password message.
Dim dbs As Database
Dim rstUserPwd As Recordset
Dim bFoundMatch As Boolean
Set dbs = CurrentDb
'query that has all the usernames and password
Set rstUserPwd = dbs.OpenRecordset("qryUserPwd")
bFoundMatch = False
If rstUserPwd.RecordCount > 0 Then
rstUserPwd.MoveFirst
'name of the access form is called 'Login'
Do While rstUserPwd.EOF = False
If rstUserPwd![UserName] = Form_Login.txtusername.Value And rstUserPwd![Password] = Form_Login.txtpassword.Value Then
bFoundMatch = True
Exit Do
End If
rstUserPwd.MoveNext
Loop
End If
'open admin form
If bFoundMatch = True
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "admin"
Else
MsgBox "Incorrect User Name or Password"
End If
Mysql has it’s own sha1 function (and others encryptions), so you can do things like “SELECT permission FROM customers WHERE sha1(key) = sha1(‘”&entered_key&”‘)”
See http://dev.mysql.com/doc/refman/5.5/en/encryption-functions.html#function_sha1
So your vba itself doesn’t need a sha algorithm.
You could use a vba/vbscript sha algorithm if you really want, if you google around you will finbd several, eg like this one http://bytes.com/topic/access/insights/906938-sha2-cryptographic-hash-algorithm-vba-vbscript