2013-04-28 1 views
0

Je suis en train d'essayer des trucs pour hacher le mot de passe pour mon site Web et j'ai expérimenté un peu et j'ai obtenu un résultat. Maintenant, je me demande si c'est en fait un bon moyen de hachage mes mots de passe.ASP.NET || Est-ce un bon moyen de hachage les mots de passe?

Mon code principal:

Imports System.Security.Cryptography 

Partial Class _Default 
Inherits System.Web.UI.Page 

Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click 
    Dim strWoordOmTeHashen As String 
    Dim strSalt1, strSalt2, strSalt3 As String 
    Dim random As New Random 

    Dim arrSalt1(255), arrSalt2(255), arrSalt3(255) As String 

    For i = 0 To 255 
     arrSalt1(i) = random.Next(1, 26).ToString 
     arrSalt2(i) = random.Next(1, 26).ToString 
     arrSalt3(i) = random.Next(1, 26).ToString 
    Next 

    For i = 0 To 255 
     arrSalt1(i) = VeranderGetalNaarLetter.VeranderGetalNaarLetter(CInt(arrSalt1(i))) 
     arrSalt2(i) = VeranderGetalNaarLetter.VeranderGetalNaarLetter(CInt(arrSalt2(i))) 
     arrSalt3(i) = VeranderGetalNaarLetter.VeranderGetalNaarLetter(CInt(arrSalt3(i))) 
    Next 

    For i = 0 To 255 
     strSalt1 &= arrSalt1(i) 
     strSalt2 &= arrSalt2(i) 
     strSalt3 &= arrSalt3(i) 
    Next 


    strWoordOmTeHashen = strSalt1 & strSalt2 & txtWoord.Text & strSalt3 

    'Sha512 zoder salt 
    Dim sham As New SHA512Managed 
    Dim result As Byte() 
    Dim data As Byte() 
    Dim hexstring As String 

    data = ASCIIEncoding.ASCII.GetBytes(strWoordOmTeHashen) 
    result = sham.ComputeHash(data) 

    For i = 0 To UBound(result) 
     hexstring &= Hex(result(i)).ToLower 
    Next 

    TextBox1.Text = hexstring 

End Sub 
End Class 

Vous remarquerez peut-être que j'appelle une fonction. J'appelle cette fonction: Classe publique VeranderGetalNaarLetter

Public Shared Function VeranderGetalNaarLetter(intSalt As Integer) As String 

    Dim strAlfabet As String = "!abcdefghijklmnopqrstuvwxyz" 
    Dim strLetter As String 

    strLetter = strAlfabet.Substring(intSalt, 1) 


    Return strLetter 
End Function 


End Class 

Tout commentaire est le bienvenu. J'espère avoir des commentaires pour améliorer ma programmation un peu. Merci à l'avance :)

Répondre

1

Bien que ce ne soit pas faux, ce n'est pas la meilleure pratique non plus. Hashing mots de passe est très fastidieux et parfois réinventer la roue ne vaut tout simplement pas la peine. Si vous devez hacher votre mot de passe, vous devez utiliser une bibliothèque déjà existante. S'il vous plaît jeter un oeil à BCrypt http://bcrypt.codeplex.com/

0

Ceci est le code que j'utilise normalement des choses de hachage, il est une fonction très simple en fait :)

Function hash(text As String) As String 
    Dim encoder As New System.Text.UnicodeEncoding 
    Dim sha256 As New System.Security.Cryptography.SHA256CryptoServiceProvider 
    Return Convert.ToBase64String(sha256.ComputeHash(encoder.GetBytes(text))) 
End Function 

Bonne chance!

+0

Oui, mais j'ai lu sur l'utilisation de sels. Je ne vous vois pas utiliser de sel. Est-ce nécessaire ou non? –

Questions connexes