|
4 | 4 |
|
5 | 5 | namespace ScottBrady91.AspNetCore.Identity
|
6 | 6 | {
|
| 7 | + /// <summary> |
| 8 | + /// ASP.NET Core Identity password hasher using the bcrypt password hashing algorithm. |
| 9 | + /// </summary> |
| 10 | + /// <typeparam name="TUser">your ASP.NET Core Identity user type (e.g. IdentityUser). User is not used by this implementation</typeparam> |
7 | 11 | public class BCryptPasswordHasher<TUser> : IPasswordHasher<TUser> where TUser : class
|
8 | 12 | {
|
9 | 13 | private readonly BCryptPasswordHasherOptions options;
|
10 | 14 |
|
| 15 | + /// <summary> |
| 16 | + /// Creates a new BCryptPasswordHasher. |
| 17 | + /// </summary> |
| 18 | + /// <param name="optionsAccessor">optional BCryptPasswordHasherOptions</param> |
11 | 19 | public BCryptPasswordHasher(IOptions<BCryptPasswordHasherOptions> optionsAccessor = null)
|
12 | 20 | {
|
13 | 21 | options = optionsAccessor?.Value ?? new BCryptPasswordHasherOptions();
|
14 | 22 | }
|
15 | 23 |
|
| 24 | + /// <summary> |
| 25 | + /// Hashes a password using bcrypt. |
| 26 | + /// </summary> |
| 27 | + /// <param name="user">not used for this implementation</param> |
| 28 | + /// <param name="password">plaintext password</param> |
| 29 | + /// <returns>hashed password</returns> |
| 30 | + /// <exception cref="ArgumentNullException">missing plaintext password</exception> |
16 | 31 | public virtual string HashPassword(TUser user, string password)
|
17 | 32 | {
|
18 | 33 | if (string.IsNullOrWhiteSpace(password)) throw new ArgumentNullException(nameof(password));
|
19 | 34 |
|
20 | 35 | return BCrypt.Net.BCrypt.HashPassword(password, options.WorkFactor, options.EnhancedEntropy);
|
21 | 36 | }
|
22 | 37 |
|
| 38 | + /// <summary> |
| 39 | + /// Verifies a plaintext password against a stored hash. |
| 40 | + /// </summary> |
| 41 | + /// <param name="user">not used for this implementation</param> |
| 42 | + /// <param name="hashedPassword">the stored, hashed password</param> |
| 43 | + /// <param name="providedPassword">the plaintext password to verify against the stored hash</param> |
| 44 | + /// <returns>If the password matches the stored password. Returns SuccessRehashNeeded if the work factor has changed</returns> |
| 45 | + /// <exception cref="ArgumentNullException">missing plaintext password or hashed password</exception> |
23 | 46 | public virtual PasswordVerificationResult VerifyHashedPassword(TUser user, string hashedPassword, string providedPassword)
|
24 | 47 | {
|
25 | 48 | if (string.IsNullOrWhiteSpace(hashedPassword)) throw new ArgumentNullException(nameof(hashedPassword));
|
|
0 commit comments