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); }
public void SignIn(СoncreteUserIdentity identity) { if (identity == null) { return; } _identity = identity; }
public IdentityService() { _identity = new СoncreteUserIdentity(null); }
public void SignOut() { //TODO: очистка прав _identity = null; }