예제 #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;
 }