Where would I haveh password in asp.net using mvc4 and EF?

therefore, some models appear in the default view. I am trying to find out if I want a hash password using the Crypto.HashPassword () method. Am I doing this in a controller or model or where? I researched how to do this, but I just find a different method, not where the action takes place. Starting with MVC and asp.net, so any point in the right direction will be a big help. Thank you in advance.

+3
source share
3 answers

I would define a user class as follows:

public class User
{
    private string PasswordHash {get; set;} //assuming your db supports serializing private properties. If not increase visibility as necessary.

    public void SetPassword(string newPassword)
    {
        PasswordHash = PasswordHasher.CreateHash(newPassword);
    }

    public bool VerifyPassword(string passwordCandidate)
    {
        return PasswordHasher.Verify(PasswordHash, passwordCandidate);
    }
}

I would not have a property User.Password, since you never store it, and there is no simple mapping between passwords and hashes.

PasswordHash . , / .


API Crypto. Crypto .

+2

- - .

, , :

  • , Crypto.HashPassword(pwd) , . , .
  • (, ), .
  • , Crypto.VerifyHashedPassword(storedHash, submittedPwd). Crypto pwd IV True, (pwd ), False, (pwd ).

MVC ASP.Net, ASP.Net Forms (, MSDN), .

+3

.

password [Encrypt (true)]. , , , Encrypt ( DbContext Saving). .

, , .

0

All Articles