public string GenerateHash(string password, PasswordAlgorithms algorithm)
 {
     switch (algorithm)
     {
     case PasswordAlgorithms.SHA256:
         return(GenerateHashWithSHA256(password));
     }
     throw new ArgumentException();
 }
Пример #2
0
        private PasswordAlgorithm CreateIfNotExistsOrGet(PasswordAlgorithms algorithm)
        {
            var name = Enum.GetName(typeof(PasswordAlgorithms), algorithm);
            var passwordAlgorithm = Repository.GetSet <PasswordAlgorithm>().FirstOrDefault(p => p.Name.ToLower().Equals(name.ToLower()));

            if (passwordAlgorithm == null)
            {
                passwordAlgorithm      = new PasswordAlgorithm();
                passwordAlgorithm.Name = name;
                Repository.Add(passwordAlgorithm);
            }
            return(passwordAlgorithm);
        }
Пример #3
0
        public User FindUser(string name, string password)
        {
            ThrowsIfEmpty(name, password);
            var userView = FindUserView(name);
            PasswordAlgorithms algorithm = (PasswordAlgorithms)Enum.Parse(typeof(PasswordAlgorithms), userView.PasswordAlgorithmName);
            var passwordHash             = PasswordService.GenerateHash(password, algorithm);

            if (userView.Name.ToLower().Equals(name.ToLower()) && userView.Password.Equals(passwordHash))
            {
                return(userView.User);
            }
            else
            {
                throw new NotFoundException();
            }
        }