Esempio n. 1
0
        public async Task <IdentityResult> CreateAsync(IdentityUser user, string password)
        {
            password = password.Trim();

            if (string.IsNullOrEmpty(password) || password.Length < 7)
            {
                return(new IdentityResult()
                {
                    Errors = new List <string> {
                        "Password must be at least 7 characters"
                    },
                    Succeeded = false
                });
            }

            using (var db = new SqlDbContext(_options))
            {
                try
                {
                    var dbUser = db.IdentityUser.FirstOrDefault(tbl => tbl.Id == user.Id);

                    if (dbUser == null)
                    {
                        user.CreatedOn = DateTime.Now;
                        // Normalize to lower to match the current user search. Or should we keep a copy of the original?
                        user.Email    = user.Email.ToLower();
                        user.UserName = user.UserName.ToLower();

                        user.PasswordHash = _hasher.HashPassword(user.Id, password);

                        db.Add(user);
                    }
                    await db.SaveChangesAsync();
                }
                catch (Exception exc)
                {
                }

                return(new IdentityResult()
                {
                    Succeeded = true
                });
            }
        }
Esempio n. 2
0
 public string Hash(string password)
 {
     return(_passwordHasher.HashPassword(null, password));
 }