コード例 #1
0
        public СoncreteUserIdentity AuthenticateUser(string login, string password)
        {
            var rep = new UserRepository();
            var passwordWithSalt = rep.GetHashAndSalt(login);

            if (passwordWithSalt == null)
            {
                throw new UnauthorizedAccessException($"Пользователь '{login}' не найден");
            }

            var dynamicSalt = passwordWithSalt.Salt;
            var staticSalt  = PasswordManager.GetStaticSalt();

            var rightPassword = passwordWithSalt.Password;
            var testPassword  = PasswordManager.Encrypt(password, dynamicSalt, staticSalt);

            if (rightPassword != testPassword)
            {
                throw new UnauthorizedAccessException("Введён неверный пароль");
            }

            var user     = rep.GetUsers(null, null, null, login, 0).FirstOrDefault();
            var identity = new СoncreteUserIdentity(user);

            return(identity);
        }
コード例 #2
0
 public void SignIn(СoncreteUserIdentity identity)
 {
     if (identity == null)
     {
         return;
     }
     _identity = identity;
 }
コード例 #3
0
 public IdentityService()
 {
     _identity = new СoncreteUserIdentity(null);
 }
コード例 #4
0
 public void SignOut()
 {
     //TODO: очистка прав
     _identity = null;
 }