示例#1
0
        public void ChangeUserPassword(ChangePasswordDto infos)
        {
            Logger.LogInformation($"Change password from user {infos.UserName}");

            Validate(infos);

            using (var context = RepositoriesFactory.CreateContext())
            {
                var local    = this.GetErrorStringLocalizer();
                var userRepo = RepositoriesFactory.GetUserRepository(context);

                var user = userRepo.GetByUserName(infos.UserName);

                if (user == null || !user.IsValid)
                {
                    throw new DaOAuthServiceException(local["ChangeUserPasswordUserInvalid"]);
                }

                if (!EncryptionService.AreEqualsSha256(
                        String.Concat(Configuration.PasswordSalt, infos.OldPassword), user.Password))
                {
                    throw new DaOAuthServiceException(local["ChangeUserPasswordPasswordInvalid"]);
                }

                if (!infos.NewPassword.Equals(infos.NewPasswordRepeat, StringComparison.Ordinal))
                {
                    throw new DaOAuthServiceException(local["ChangeUserPasswordDifferentsNewPasswords"]);
                }

                if (!infos.NewPassword.IsMatchPasswordPolicy())
                {
                    throw new DaOAuthServiceException(local["ChangeUserPasswordNewPasswordDontMatchPolicy"]);
                }

                user.Password = EncryptionService.Sha256Hash(String.Concat(Configuration.PasswordSalt, infos.NewPassword));

                userRepo.Update(user);

                context.Commit();
            }
        }
示例#2
0
        public UserDto GetUser(LoginUserDto credentials)
        {
            Logger.LogInformation($"Try to log user {credentials.UserName}");

            Validate(credentials);

            UserDto result = null;

            using (var c = RepositoriesFactory.CreateContext())
            {
                var repo = RepositoriesFactory.GetUserRepository(c);
                var user = repo.GetByUserName(credentials.UserName);

                if (user != null && user.IsValid && EncryptionService.AreEqualsSha256(
                        String.Concat(Configuration.PasswordSalt, credentials.Password), user.Password))
                {
                    result = user.ToDto();
                    Logger.LogInformation($"Log successfull for user {credentials.UserName}");
                }
            }

            return(result);
        }