예제 #1
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="password"></param>
 /// <param name="confPass"></param>
 /// <param name="exception"></param>
 /// <returns></returns>
 public override bool ValidPass(string password, string confPass, CreationException exception)
 {
     var valid = confPass == password && password?.Length >= 8;
     if ( !valid )
     {
         exception.AddError("Invalid password", "Please enter a " +
             "password with 8 or more characters");
     }
     return valid;
 }
예제 #2
0
        /// <summary>
        /// cannot have spaces, must be alphanumeric, can have underscore, 
        /// and cannot have more than 24 characters 
        /// </summary>
        /// <param name="userName">The user name supplied by view</param>
        /// <param name="exception">Error message container</param>
        /// <returns>Wether the user name is valid</returns>
        public override bool ValidUser(string userName, CreationException exception)
        {
            // one or more alphanumeric characters and an underscore
            Regex validUser = new Regex(@"^[a-zA-Z0-9_]+$");
            // don't count the beginning and ending whitespace
            userName = userName?.Trim();
            int userMax = 256;
            int userMin = 3;
            bool valid = userName != null && 
                         validUser.IsMatch(userName) &&
                         userName.Length > userMin && 
                         userName.Length < userMax;
            if ( !valid )
            {
                exception.AddError("Invalid user name", "A user name can only" +
                    $" have alphanumeric characters, be less than {userMax} " +
                    $"characters, and be more than {userMin} characters");
            }

            return valid;
        }