Hash and salt passwords in C#

后端 未结 14 1827
野趣味
野趣味 2020-11-22 04:00

I was just going through one of DavidHayden\'s articles on Hashing User Passwords.

Really I can\'t get what he is trying to achieve.

Here is his code:

<
14条回答
  •  既然无缘
    2020-11-22 04:35

    I have made a library SimpleHashing.Net to make the process of hashing easy with basic classes provided by Microsoft. Ordinary SHA is not really enough to have passwords stored securely anymore.

    The library use the idea of hash format from Bcrypt, but since there is no official MS implementation I prefer to use what's available in the framework (i.e. PBKDF2), but it's a bit too hard out of the box.

    This is a quick example how to use the library:

    ISimpleHash simpleHash = new SimpleHash();
    
    // Creating a user hash, hashedPassword can be stored in a database
    // hashedPassword contains the number of iterations and salt inside it similar to bcrypt format
    string hashedPassword = simpleHash.Compute("Password123");
    
    // Validating user's password by first loading it from database by username
    string storedHash = _repository.GetUserPasswordHash(username);
    isPasswordValid = simpleHash.Verify("Password123", storedHash);
    

提交回复
热议问题