aboutsummaryrefslogtreecommitdiff
path: root/backend/api/api/Models/PasswordCrypt.cs
blob: 016fde51a9e445ff5978fcf15cec011b5724e3eb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
namespace api.Models
{
    public class PasswordCrypt
    {
        private static int difficulty = 10;

        public static String hashPassword(String password)
        {
            String salt = BCrypt.Net.BCrypt.GenerateSalt(difficulty);
            String passwordHash = BCrypt.Net.BCrypt.HashPassword(password, salt);

            return passwordHash;
        }
        public static Boolean checkPassword(String plainText,String hash)
        {
            Boolean verified = false;

            if (hash == null || !hash.StartsWith("$2a$"))
                throw new ArgumentException("invalid hash");

            verified=BCrypt.Net.BCrypt.Verify(plainText, hash);

            return verified;
            
        }
    }
}