public string PasswordChecker(string Password)
        {
            List <int> nonSelectedIndexes = new List <int>(Enumerable.Range(0, Password.Length));
            Random     rand = new Random();

            if (!Password.Any(x => char.IsDigit(x)))
            { //does not contain digit
                char[] pass = Password.ToCharArray();
                int    pos  = nonSelectedIndexes[rand.Next(nonSelectedIndexes.Count)];
                nonSelectedIndexes.Remove(pos);
                pass[pos] = Convert.ToChar(rand.Next(10) + '0');
                Password  = new string(pass);
            }

            if (!Password.Any(x => char.IsLower(x)))
            { //does not contain lower
                char[] pass = Password.ToCharArray();
                int    pos  = nonSelectedIndexes[rand.Next(nonSelectedIndexes.Count)];
                nonSelectedIndexes.Remove(pos);
                pass[pos] = Convert.ToChar(rand.Next(26) + 'a');
                Password  = new string(pass);
            }

            if (!Password.Any(x => char.IsUpper(x)))
            { //does not contain upper
                char[] pass = Password.ToCharArray();
                int    pos  = nonSelectedIndexes[rand.Next(nonSelectedIndexes.Count)];
                nonSelectedIndexes.Remove(pos);
                pass[pos] = Convert.ToChar(rand.Next(26) + 'A');
                Password  = new string(pass);
            }

            return(Password);
        }
        private int PasswordStrengh()
        {
            var strengh = 0;

            if (Password.Any(c => char.IsDigit(c)))
            {
                strengh++;
            }

            if (Password.Any(c => char.IsUpper(c)))
            {
                strengh++;
            }

            if (Password.Any(c => char.IsLower(c)))
            {
                strengh++;
            }

            if (Password.Any(c => char.IsSymbol(c)))
            {
                strengh++;
            }
            return(strengh);
        }
Esempio n. 3
0
        public Tuple <bool, string> IsValidPassword()
        {
            TextBlock.Visibility = Visibility.Visible;

            if (Password.Contains(" "))
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password cannot contain white spaces."));
            }

            if (!Password.Any(char.IsNumber))
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password must contain at least one numeric char."));
            }

            // perhaps the requirements meant to be 1 capital letter?
            //if (password.Count(char.IsUpper) != 1)
            if (!Password.Any(char.IsUpper))
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password must contain at least 1 capital letter."));
            }

            if (Password.Length < 8)
            {
                return(new Tuple <bool, string>(false, TextBlock.Text = "Password is too short, must be\n at least 8 characters."));
            }

            return(new Tuple <bool, string>(true, TextBlock.Text = string.Empty));
        }
Esempio n. 4
0
 public void ValidatePassword()
 {
     if (Password.Trim().Length < 8)
     {
         ValidationMessage = "Password must be at least eight characters long";
     }
     else if (Password.Trim().Length > 20)
     {
         ValidationMessage = "Password cannot be more than twenty characters long";
     }
     else if (!Password.Any(char.IsUpper))
     {
         ValidationMessage = "Password must contain at least one upper-case character";
     }
     else if (!Password.Any(char.IsLower))
     {
         ValidationMessage = "Password must contain at least one lower-case character";
     }
     else if (!Password.Any(char.IsNumber))
     {
         ValidationMessage = "Password must contain at least one number";
     }
     else
     {
         ValidationMessage = "Password is secure";
     }
 }
        protected override PageContent getContent()
        {
            if (Password.Any())
            {
                return(new UiPageContent(
                           pageLoadPostBack: PostBack.CreateFull(
                               modificationMethod: () => logIn(HideWarnings),
                               actionGetter: () => new PostBackAction(new ExternalResource(ReturnUrl)))).Add(new Paragraph("Please wait.".ToComponents())));
            }

            return(FormState.ExecuteWithDataModificationsAndDefaultAction(
                       PostBack.CreateFull(modificationMethod: () => logIn(false), actionGetter: () => new PostBackAction(new ExternalResource(ReturnUrl)))
                       .ToCollection(),
                       () => new UiPageContent(contentFootActions: new ButtonSetup("Log In").ToCollection()).Add(
                           FormItemList.CreateStack(
                               items: new TextControl(
                                   "",
                                   true,
                                   setup: TextControlSetup.CreateObscured(),
                                   validationMethod: (postBackValue, validator) => {
                // NOTE: Using a single password here is a hack. The real solution is being able to use System Manager credentials, which is a goal.
                var passwordMatch = postBackValue == ConfigurationStatics.SystemGeneralProvider.IntermediateLogInPassword;
                if (!passwordMatch)
                {
                    validator.NoteErrorAndAddMessage("Incorrect password.");
                }
            }).ToFormItem(label: "Enter your password for this non-live installation".ToComponents())
                               .ToCollection()))));
        }
Esempio n. 6
0
 public bool ValidatePassword()
 {
     if (Password.Length < 5)
     {
         return(false);
     }
     else if (!(Password.Any(char.IsUpper)))
     {
         return(false);
     }
     return(true);
 }
            protected override void init()
            {
                if (!ConfigurationStatics.IsIntermediateInstallation)
                {
                    throw new ApplicationException("installation type");
                }

                if (Password.Any() && Password != ConfigurationStatics.SystemGeneralProvider.IntermediateLogInPassword)
                {
                    throw new ApplicationException("password");
                }
            }
        public bool DataValidate()
        {
            //Regex for detecting special characters Lower cases, Upper cases, numbers only
            var regexItem = new Regex("^[a-zA-Z0-9]*$");

            if (!regexItem.IsMatch(FirstName) || !regexItem.IsMatch(LastName))
            {
                _dialogService.ShowMessage("First Name and Last Name must not have these special characters (!@#$%^&)", "Error");
                return(false);
            }

            else if (Password.Length < 8 || Password.Length > 15)
            {
                _dialogService.ShowMessage("Password must have from 8 to 15 characters", "Error");
                return(false);
            }

            else if (!Password.Any(char.IsLower))
            { //Check lowercase, using LINQ
                _dialogService.ShowMessage("Password must have at least one lowercase letter", "Error");
                return(false);
            }

            else if (!Password.Any(char.IsUpper)) //Check lowercase, using LINQ
            {
                _dialogService.ShowMessage("Password must have at least one uppercase letter", "Error");
                return(false);
            }

            else if (FindRepetitives(Password))
            {
                _dialogService.ShowMessage("Password must not have repetitive any sequence of character", "Error");
                return(false);
            }

            else if ((StartDate - DateTime.Now).TotalDays < 30)
            {
                _dialogService.ShowMessage("Stating that is too early to create an account", "Error");
                return(false);
            }

            else if (StartDate < DateTime.Now)
            {
                _dialogService.ShowMessage("A past date is not allowed.", "Error");
                return(false);
            }

            else
            {
                return(true);
            }
        }
Esempio n. 9
0
 private bool CanTryLogin(object parameter)
 {
     Password = (parameter as PasswordBox).Password;
     if (String.IsNullOrEmpty(Username) || String.IsNullOrEmpty(Password))
     {
         return(false);
     }
     if (Username.Any(x => Char.IsWhiteSpace(x)) || Password.Any(x => Char.IsWhiteSpace(x)))
     {
         return(false);
     }
     return(true);
 }
Esempio n. 10
0
        public bool Validate(out ICollection <ResultError> errors)
        {
            errors = new List <ResultError>();

            if (string.IsNullOrWhiteSpace(Email))
            {
                errors.Add(Errors.ValidationRequired(nameof(Email)));
            }

            if (Email != null && !Email.Contains("@"))
            {
                errors.Add(Errors.ValidationInvalidEmail(nameof(Email)));
            }

            if (string.IsNullOrWhiteSpace(Password))
            {
                errors.Add(Errors.ValidationRequired(nameof(Password)));
            }

            if (Password != null && Password.Length < 7)
            {
                errors.Add(Errors.ValidationMinLength(nameof(Password), 7));
            }

            if (Password != null && !Password.Any(c => char.IsUpper(c)))
            {
                errors.Add(Errors.ValidationMustContainUpper(nameof(Password)));
            }

            if (Password != null && !Password.Any(c => char.IsLower(c)))
            {
                errors.Add(Errors.ValidationMustContainLower(nameof(Password)));
            }

            if (Password != null && !Password.Any(c => char.IsNumber(c)))
            {
                errors.Add(Errors.ValidationMustContainNumber(nameof(Password)));
            }

            if (ConfirmPassword != Password)
            {
                errors.Add(Errors.ValidationPasswordMismatch(nameof(ConfirmPassword)));
            }

            if (errors.Count > 0)
            {
                return(false);
            }

            return(true);
        }
Esempio n. 11
0
        public async Task ValidatePassword()
        {
            IsPasswordNotValidated = false;

            if (Password == null ||
                !Password.Any(char.IsDigit) &&
                Password.Length < 6)
            {
                PasswordNotValidatedMessage =
                    LoginAndRegisterResources.PasswordIsNotValid;
                IsPasswordNotValidated = true;
            }
            await ValidateRepeatedPassword();
        }
Esempio n. 12
0
        private Tuple <bool, string> isPasswordValid()
        {
            bool   isValid = false;
            string message = "La contraseña debe tener mínimo 6 caracteres, 1 mayúscula, 1 minúscula y 1 número";

            if (Password.Length >= 6 && Password.Any(ch => char.IsUpper(ch)) && Password.Any(ch => char.IsLower(ch)) && Password.Any(ch => char.IsNumber(ch)))
            {
                isValid = true;
                message = "La contraseña es correcta";
            }

            Tuple <bool, string> result = new Tuple <bool, string>(isValid, message);

            return(result);
        }
        private bool PasswordValidation()
        {
            bool IsValid;

            if (Password.Length >= PasswordLength && Password.Any(char.IsUpper) && Password.Any(char.IsLower) && Password.Any(char.IsLetterOrDigit))
            {
                IsValid = true;
            }
            else
            {
                IsValid = false;
            }

            return(IsValid);
        }
 public bool ValidatePassword()
 {
     if (Password == null || Password.Trim().Length == 0)
     {
         PasswordValidationMessage = "\u2022 Password cannot be empty. \n";
     }
     else
     {
         PasswordValidationMessage = null;
         if (Password.Trim().Length < 8)
         {
             PasswordValidationMessage += "\u2022 Password must be at least 8 characters long. \n";
         }
         if (Password.Trim().Length > 20)
         {
             PasswordValidationMessage += "\u2022 Password cannot be more than 20 characters long. \n";
         }
         if (!(Password.Any(char.IsUpper)))
         {
             PasswordValidationMessage += "\u2022 Password must contain at least one uppercase letter. \n";
         }
         if (!(Password.Any(char.IsLower)))
         {
             PasswordValidationMessage += "\u2022 Password must contain at least one lowercase letter. \n";
         }
         if (!(Password.Any(char.IsNumber)))
         {
             PasswordValidationMessage += "\u2022 Password must contain at least one number. \n";
         }
         if (!(Password.Any(char.IsSymbol) || Password.Any(char.IsPunctuation)))
         {
             PasswordValidationMessage += "\u2022 Password must contain at least one symbol. \n";
         }
         if ((Password.Any(char.IsWhiteSpace)))
         {
             PasswordValidationMessage += "\u2022 Password cannot contain spaces. \n";
         }
     }
     if (PasswordValidationMessage == null)
     {
         PasswordValidationMessage = "\u2022 Password is acceptable. \n";
         return(true);
     }
     else
     {
         return(false);
     }
 }
Esempio n. 15
0
        public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
        {
            List <ValidationResult> result = new List <ValidationResult>();

            if (Captcha != (string)HttpContext.Current.Session["captcha"])
            {
                result.Add(new ValidationResult(Resources.Resource.InvalidCaptcha));
            }
            if (Password != null && Password != RepeatPassword)
            {
                result.Add(new ValidationResult(Resources.Resource.PasswordsDoNotMatch));
            }
            if (Role == "Admin")
            {
                throw new HttpException(404, "Page Not Found");
            }
            else if (Password.Any(c => char.IsWhiteSpace(c)))
            {
                result.Add(new ValidationResult(Resources.Resource.NoWhiteSpaces));
            }
            return(result);
        }
Esempio n. 16
0
 public IEnumerable <ValidationResult> Validate(ValidationContext validationContext)
 {
     if (this.InputName == null)
     {
         if (Password.Length < 8)
         {
             yield return(new ValidationResult($"wachtwoord moet meer dan acht tekens hebben"));
         }
         if (!Password.Any(C => char.IsUpper(C) || char.IsLower(C) || char.IsDigit(C)))
         {
             yield return(new ValidationResult($"Wachtwoord moet minimaal een kleine en grote letter bevatten en een cijfer hebben"));
         }
         if (UserManager.CheckEmail(this))
         {
             yield return(new ValidationResult(@"Email is al in gebruik"));
         }
         if (UserManager.CheckUserName(this))
         {
             yield return(new ValidationResult(@"Gebruikersnaam is al in gebruik"));
         }
     }
 }
        public override void IsValid()
        {
            if (!Email.EndsWith("@aiub.edu"))
            {
                throw new Exception("Invaild Email.You need an email address with aiub.edu domain");
            }

            var FacultyIdFormat = new Regex("\\d{4}-\\d{4}-[1-3]$");

            if (!FacultyIdFormat.IsMatch(AcademicId))
            {
                throw new Exception("Invaild ID format.Please check your academic ID");
            }

            if (Password.Length < 6)
            {
                throw new Exception("Weak password. Password length should be 6 at least");
            }
            if (!Password.Any(char.IsUpper) || !Password.Any(char.IsLower) || !Password.Any(char.IsDigit))
            {
                throw new Exception("Weak password.please create a password using combintation of uppercase and lowercase letters and numbers");
            }
        }
        private int VerificarFortaleza()
        {
            // strengh = (muy facil, facil, medio, fuerte, muy fuerte)
            var fortaleza = 0;

            // Longitud (>=6 +1)
            if (Password.Length >= 6)
            {
                fortaleza++;
            }

            // Mayusculas (+1)
            if (Password.Any(c => char.IsUpper(c)))
            {
                fortaleza++;
            }

            // Minusculas (+1)
            if (Password.Any(c => char.IsLower(c)))
            {
                fortaleza++;
            }

            // Numeros (+1)
            if (Password.Any(c => char.IsDigit(c)))
            {
                fortaleza++;
            }

            // Simbolos (+1)
            if (Password.Any(c => char.IsSymbol(c)))
            {
                fortaleza++;
            }

            return(fortaleza);
        }
        public string ValidatorForm()
        {
            if (Password == null || Password.Length < 6)
            {
                return("minimum six characters");
            }
            if (Password == null || Password.Any(char.IsDigit) != true || Password.Any(char.IsLetter) != true)
            {
                return("the password must have numbers and letters");
            }

            if ((Password == null || RePassword == null) || Password != RePassword)
            {
                return("the passwords are not the same");
            }

            if ((Email == null || ReEmail == null) || Email != ReEmail)
            {
                return("emails are not the same");
            }

            Regex regex  = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
            Match match  = regex.Match(Email);
            Match match2 = regex.Match(ReEmail);

            if (!match.Success)
            {
                return("email is not in the correct format ('*****@*****.**')");
            }

            if (!match2.Success)
            {
                return("Reemail is not in the correct format ('*****@*****.**')");
            }

            return("");
        }
 public AuthentificationDialog()
 {
     InitializeComponent();
     OkButtonClick  = new RelayCommand(() => DialogResult = true, () => Name.Any() && Password.Any());
     button.Command = OkButtonClick;
 }
Esempio n. 21
0
 public string GetConnectionString()
 {
     return(Type switch
     {
         Database.Mssql =>
         $"Server={Server} ; {(Username.Any() ? "user id=" + Username + ";" : "")} {(Password.Any() ? "Password="******";" : "")} Database={DataBase}; {(!Username.Any() ? "Trusted_Connection=True" : "")}; Enlist=true",
         Database.Postgres =>
         $"Server={Server} ; Port={(Port == 0 ? "" : Port.ToString())}; {(Username.Any() ? "user id=" + Username + ";" : "")} {(Password.Any() ? "Password="******";" : "")} Database={DataBase}; {(!Username.Any() ? "Trusted_Connection=True" : "")}; Enlist=true",
         Database.Mysql => "",
         Database.SqlLite => "",
         _ => throw new NotImplementedException("Database not recognized.")
     });
Esempio n. 22
0
        private void ConfigureValidationRules()
        {
            Validator.AddRequiredRule(() => UserName, "User Name is required");

            Validator.AddAsyncRule(nameof(UserName),
                                   async() =>
            {
                var isAvailable = await UserRegistrationService.IsUserNameAvailable(UserName).ToTask();

                return(RuleResult.Assert(isAvailable,
                                         string.Format("User Name {0} is taken. Please choose a different one.", UserName)));
            });

            Validator.AddRequiredRule(() => FirstName, "First Name is required");

            Validator.AddRequiredRule(() => LastName, "Last Name is required");

            Validator.AddRequiredRule(() => Email, "Email is required");

            Validator.AddRule(nameof(Email),
                              () =>
            {
                const string regexPattern =
                    @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$";
                return(RuleResult.Assert(Regex.IsMatch(Email, regexPattern),
                                         "Email must by a valid email address"));
            });

            Validator.AddRequiredRule(() => Password, "Password is required");

            Validator.AddRule(nameof(Password),
                              () => RuleResult.Assert(Password.Length >= 6,
                                                      "Password must contain at least 6 characters"));

            Validator.AddRule(nameof(Password),
                              () => RuleResult.Assert((!Password.All(char.IsLower) &&
                                                       !Password.All(char.IsUpper) &&
                                                       !Password.All(char.IsDigit)),
                                                      "Password must contain both lower case and upper case letters"));

            Validator.AddRule(nameof(Password),
                              () => RuleResult.Assert(Password.Any(char.IsDigit),
                                                      "Password must contain at least one digit"));

            Validator.AddRule(nameof(PasswordConfirmation),
                              () =>
            {
                if (!string.IsNullOrEmpty(Password) && string.IsNullOrEmpty(PasswordConfirmation))
                {
                    return(RuleResult.Invalid("Please confirm password"));
                }

                return(RuleResult.Valid());
            });

            Validator.AddRule(nameof(Password),
                              nameof(PasswordConfirmation),
                              () =>
            {
                if (!string.IsNullOrEmpty(Password) && !string.IsNullOrEmpty(PasswordConfirmation))
                {
                    return(RuleResult.Assert(Password == PasswordConfirmation, "Passwords do not match"));
                }

                return(RuleResult.Valid());
            });

            Validator.AddChildValidatable(() => InterestSelectorViewModel);
        }
Esempio n. 23
0
        public bool RCheckInformation()
        {
            if (FirstName != null)
            {
                if (FirstName.Trim().Length < 2)
                {
                    ValidationMessage = "First Name must be at least two characters long";
                    return(false);

                    //IsFirstNameVisible = Visibility.Visible;
                }
            }
            if (LastName != null)
            {
                if (LastName.Trim().Length < 2)
                {
                    ValidationMessage = "Last Name must be at least two characters long";
                    return(false);
                    // IsLastNameVisible = Visibility.Visible;
                }
            }
            if (Password != null)
            {
                if (Password.Trim().Length < 2)
                {
                    ValidationMessage = "Password must be at least two characters long";
                    return(false);

                    // IsPasswordVisible = Visibility.Visible;
                }
                else if (Password.Trim().Length > 20)
                {
                    ValidationMessage = "Password cannot be m9ore than twenty characters long";
                    return(false);
                    // IsPasswordVisible = Visibility.Visible;
                }
                else if (!Password.Any(char.IsUpper))
                {
                    ValidationMessage = "Password must contain at least one upper-case character";
                    return(false);
                    //  IsPasswordVisible = Visibility.Visible;
                }
                else if (!Password.Any(char.IsLower))
                {
                    ValidationMessage = "Password must contain at least one lower-case character";
                    return(false);
                    //  IsPasswordVisible = Visibility.Visible;
                }
                else if (!Password.Any(char.IsNumber))
                {
                    ValidationMessage = "Password must contain at least one number";
                    return(false);
                    // IsPasswordVisible = Visibility.Visible;
                }
                if (ConfirmPassword != null)
                {
                    if (Password != ConfirmPassword)
                    {
                        ValidationMessage = "Password do not match";
                        return(false);
                        // IsConfirmPasswordVisible = Visibility.Collapsed;
                    }

                    else
                    {
                        ValidationMessage = "Password is secure";

                        return(true);
                    }
                }
                else if (ConfirmPassword == null)
                {
                    return(false);
                }
            }

            else
            {
                ValidationMessage = "Please Enter All Value";
                return(false);
            }

            return(true);
        }
        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            _passwordBox = (PasswordBox)GetTemplateChild("PasswordBox");
            if (_passwordBox == null)
            {
                throw new NullReferenceException();
            }

            _validationStackPanel = (StackPanel)GetTemplateChild("ValidationStackPanel");
            if (_validationStackPanel == null)
            {
                throw new NullReferenceException();
            }

            _lowercaseTextBlock = (TextBlock)GetTemplateChild("LowercaseTextBlock");
            if (_lowercaseTextBlock == null)
            {
                throw new NullReferenceException();
            }

            _uppercaseTextBlock = (TextBlock)GetTemplateChild("UppercaseTextBlock");
            if (_uppercaseTextBlock == null)
            {
                throw new NullReferenceException();
            }

            _numberTextBlock = (TextBlock)GetTemplateChild("NumberTextBlock");
            if (_numberTextBlock == null)
            {
                throw new NullReferenceException();
            }

            _minCharsTextBlock = (TextBlock)GetTemplateChild("MinCharsTextBlock");
            if (_minCharsTextBlock == null)
            {
                throw new NullReferenceException();
            }

            if (!string.IsNullOrEmpty(MinimumCharCountText))
            {
                _minCharsTextBlock.Text = MinimumCharCountText;
            }

            _passwordBox.GotFocus += (object sender, RoutedEventArgs e) => _validationStackPanel.Visibility = Visibility.Visible;

            _passwordBox.LostFocus += (object sender, RoutedEventArgs e) => _validationStackPanel.Visibility = Visibility.Collapsed;

            _passwordBox.PasswordChanged += (object sender, RoutedEventArgs e) =>
            {
                Password = _passwordBox.Password;

                if (string.IsNullOrEmpty(Password))
                {
                    _lowercaseTextBlock.Foreground = _uppercaseTextBlock.Foreground = _numberTextBlock.Foreground = _minCharsTextBlock.Foreground = RedColor;
                    IsValidPassword = false;
                }
                else
                {
                    var HasValidLowercase    = Password.Any(c => char.IsLower(c));
                    var HasValidUppercase    = Password.Any(c => char.IsUpper(c));
                    var HasValidNumber       = Password.Any(c => char.IsNumber(c));
                    var HasValidMinimumChars = (Password.Length >= MinimumCharCount);

                    _lowercaseTextBlock.Foreground = (HasValidLowercase) ? GreenColor : RedColor;
                    _uppercaseTextBlock.Foreground = (HasValidUppercase) ? GreenColor : RedColor;
                    _numberTextBlock.Foreground    = (HasValidNumber) ? GreenColor : RedColor;
                    _minCharsTextBlock.Foreground  = (HasValidMinimumChars) ? GreenColor : RedColor;

                    IsValidPassword = (HasValidLowercase && HasValidUppercase && HasValidNumber && HasValidMinimumChars);
                }
            };
        }