Hi,
I've had a couple of PMs regarding how I had handled authentication for migrated Snitz users, so thought I'd repost here so that everyone has the information:
I'm not sure how it will relate now that 1.9.3 uses Membership providers, though it will depend on how you have set them up. I had implemented this for use with 1.9.1.8 integrated into a site with an existing membership provider that used a hash other than SHA256.
The route I took was to set every user up in my membership provider with a long and obscure password (eg, something like 'dhsaklhqwnkhasuzbklsdf8238') and also setup a new table that contains the users Snitz username and password hash.
When the user comes to log in, run your login as normal, however if the login fails at all then run the following process:
1. Check the users current password to see if it is the same as your obscure default password (using an extra .authenticate call).
2. If it is the same, then you need to check the users password against their Snitz account. You'll need to create a hash of the password the user entered in order to authenticate the user
3. If the password entered matches the users account in the Snitz account table, then set their main account to the password they just entered and log them in as normal.
4. If their password does not match, then report a log in failure as normal.
If the user decides to use the forgotten password, then just set a random password and send them that, along with a note telling them to change it once they have logged in.
I've included some code below as an example of converting a plain text password into the correct Hash value for Snitz.
NOTE: Not sure if the same would apply to the SHA256 hash generated in the membership provider, however I found that the hash being produced below gave me a '-' seperated result, while Snitz has the hash without the '-' character.
Code:
LegacyUserAuth(username, ComputeHashValue(Convert2ByteArray(password)))
Code:
Function Convert2ByteArray(ByVal strInput As String) As Byte()
Dim intCounter As Integer
Dim arrChar As Char()
arrChar = strInput.ToCharArray()
Dim arrByte(arrChar.Length - 1) As Byte
For intCounter = 0 To arrByte.Length - 1
arrByte(intCounter) = Convert.ToByte(arrChar(intCounter))
Next
Return arrByte
End Function
Public Function ComputeHashValue(ByVal data() As Byte) As String
Dim tmp As String
Dim hashAlg As SHA256 = SHA256.Create()
Dim hashvalue() As Byte = hashAlg.ComputeHash(data)
tmp = BitConverter.ToString(hashvalue).Replace("-", "")
Return tmp
End Function