Beispiel #1
0
        private bool CheckValid(string username, string password)
        {
            //Convert input to MD5 hash
            string hash = Encryption.GetMD5Hash(password);

            bool valid = false;
            //Read all users from file
            List <User> users = DataUtilities.GetUsersFromDB();

            foreach (User user in users)
            {
                if (user.Username.ToLower().Equals(username.ToLower()) && user.Password.Equals(hash))
                {
                    valid        = true;
                    loggedInUser = user;
                }
            }
            return(valid);
        }
Beispiel #2
0
        private bool ValidateForm()
        {
            //Check all fields are filled
            if (!AllFieldsFilled())
            {
                crdError.Visibility = Visibility.Visible;
                lblError.Text       = "Please complete all fields";
                return(false);
            }

            //Check username isn't already used
            if (DataUtilities.GetUsersFromDB().Any(u => u.Username.ToLower().Equals(txtUsername.Text.ToLower())))
            {
                crdError.Visibility = Visibility.Visible;
                lblError.Text       = "Username already taken";
                return(false);
            }

            //Password must be at least 8 characters and have 1 uppercase and 1 lowercase and 1 digit
            char[] passwordChars = txtPassword.Password.ToCharArray();
            if (!(passwordChars.Length >= 8 && passwordChars.Where(c => Char.IsUpper(c)).ToList().Count >= 1 && passwordChars.Where(c => Char.IsLower(c)).ToList().Count >= 1 && passwordChars.Where(c => Char.IsDigit(c)).ToList().Count >= 1))
            {
                crdError.Visibility = Visibility.Visible;
                lblError.Text       = "Password must be at least 8 characters and contain 1 uppercase character, 1 lowercase character and 1 digit";
                return(false);
            }

            //Check passwords match
            if (!txtPassword.Password.Equals(txtConfirmPassword.Password))
            {
                crdError.Visibility = Visibility.Visible;
                lblError.Text       = "Passwords do not match";
                return(false);
            }


            return(true);
        }