Example #1
0
        public virtual async Task <Execute> ChangePasswordAsync(PasswordChangeEntity info)
        {
            var result = new Execute();
            var user   = await UsersBusiness.GetByKeyAsync(TicketManager.UserKey);

            if (user == null)
            {
                result.AddError(Resources.Authentication.InvalidUserPassword);
                return(result);
            }

            if (!await VerifyPasswordHashAsync(user, info.PasswordCurrent))
            {
                result.AddError(Resources.Authentication.PasswordNotMatch);
                return(result);
            }

            if (info.PasswordNew != info.PasswordConfirm)
            {
            }

            user.Action       = EntityAction.Update;
            user.PasswordHash = await GetPasswordHashAsync(user, info.PasswordNew);

            result.AddMessage(await UsersBusiness.SaveAsync(user));

            return(result);
        }
Example #2
0
        public async Task <Execute> ValidatePasswordAsync(string email, string password)
        {
            var policy = new PasswordPolicesEntity();
            var result = new Execute();

            if (password.Length < policy.MinLength)
            {
                result.AddError(Resources.Messages.Password_MinLengthInvalid);
            }

            if (password.Length > policy.MaxLength)
            {
                result.AddError(Resources.Messages.Password_MaxLengthExceeded);
            }

            if (policy.RequireNumericChar && !password.ContainsNumericCharacters())
            {
                result.AddError(Resources.Messages.Password_NumericCharRequired);
            }

            if (policy.RequireLowercaseChar && !password.ContainsLowerCaseLetters())
            {
                result.AddError(Resources.Messages.Password_LowercaseCharRequired);
            }

            if (policy.RequireUppercaseChar && !password.ContainsUpperCaseLetters())
            {
                result.AddError(Resources.Messages.Password_UppercaseCharRequired);
            }

            if (policy.RequirePunctuationChar && !password.ContiansPunctuationCharacters())
            {
                result.AddError(Resources.Messages.Password_PunctuationCharRequired);
            }

            if (!policy.AllowSpaces && password.ContainsSpaces())
            {
                result.AddError(Resources.Messages.Password_SpaceNotAllowed);
            }

            if (!policy.AllowNonAscii && password.ContainsNonAsciiCharacters())
            {
                result.AddError(Resources.Messages.Password_NonAsciiNotAllowed);
            }

            if (!policy.ShouldNotMatchUserId)
            {
                var userMail = email.Split('@').First();

                if (password.Contains(userMail, StringComparison.InvariantCultureIgnoreCase))
                {
                    result.AddError(Resources.Messages.Password_ShouldNotMatchUserId);
                }
            }

            return(await Task.FromResult(result));
        }