Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
deleted 745 characters in body
Source Link
HelpNeeder
  • 6.5k
  • 26
  • 95
  • 160

I am trying to make sure that user uses at least 6 characters as a password in my program.

I know how to set maximum size by using MaxLength, but how I do this for the minimum length?

EDIT: How do I check if a string has less or more than 6 characters?

Small bug - when I start typing password I am being presented that password is too short until person entered 6 characters. When 6 or more characters is entered I am showing that password is valid. But, when I type 6 characters, and then remove, the check only react when there is 4 characters. But shouldn't it be tricked when there is less than 6 characters?

protected void KeyDownCheck(object sender, KeyEventArgs e) { bool validPass = txtPassword.Text.Length < 6; if (validPass) lblMessage.Text = "Password can not be shorter than 6 characters!"; else lblMessage.Text = "Password is valid."; } 

I am trying to make sure that user uses at least 6 characters as a password in my program.

I know how to set maximum size by using MaxLength, but how I do this for the minimum length?

EDIT: How do I check if a string has less or more than 6 characters?

Small bug - when I start typing password I am being presented that password is too short until person entered 6 characters. When 6 or more characters is entered I am showing that password is valid. But, when I type 6 characters, and then remove, the check only react when there is 4 characters. But shouldn't it be tricked when there is less than 6 characters?

protected void KeyDownCheck(object sender, KeyEventArgs e) { bool validPass = txtPassword.Text.Length < 6; if (validPass) lblMessage.Text = "Password can not be shorter than 6 characters!"; else lblMessage.Text = "Password is valid."; } 

I am trying to make sure that user uses at least 6 characters as a password in my program.

I know how to set maximum size by using MaxLength, but how I do this for the minimum length?

deleted 441 characters in body
Source Link
HelpNeeder
  • 6.5k
  • 26
  • 95
  • 160

I am trying to make sure that user uses at least 6 characters as a password in my program.

I know how to set maximum size by using MaxLength, but how I do this for the minimum length?

EDIT: How do I check if a string has less or more than 6 characters?

Small bug - when I start typing password I am being presented that password is too short until person entered 6 characters. When 6 or more characters is entered I am showing that password is valid. But, when I type 6 characters, and then remove, the check only react when there is 4 characters. But shouldn't it be tricked when there is less than 6 characters?

protected void OnPasswordKeydownKeyDownCheck(object sender, KeyEventArgs e) { bool isValidvalidPass = txtPassword.Text.Length < 6; lblMessage.Visible = isValid; btnAuthenticate.Visible = isValid; } 

Button code:

private void btnAuthenticate_Click(object sender, EventArgs e) { lblMessage.Text = string.Empty; if (string.IsNullOrEmpty(txtUserName.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text)) { lblMessage.Text = "Please fill out both fields!";  }   else if (txtUserName.Text == txtPassword.Text) { lblMessage.Text = "User Name and Password must be different!"; } else if (txtPassword.Text.Length < 6validPass) { lblMessage.Text = "Password can not be shorter than 6 characters!"; txtPassword.Focus();   }  else  {  Result = new AuthenticateUser();  Result.UserName = txtUserName.Text; ResultlblMessage.PasswordText = txtPassword.Text;  "Password is thisvalid.Close(); }"; } 

I am trying to make sure that user uses at least 6 characters as a password in my program.

I know how to set maximum size by using MaxLength, but how I do this for the minimum length?

EDIT: How do I check if a string has less or more than 6 characters?

protected void OnPasswordKeydown(object sender, KeyEventArgs e) { bool isValid = txtPassword.Text.Length < 6; lblMessage.Visible = isValid; btnAuthenticate.Visible = isValid; } 

Button code:

private void btnAuthenticate_Click(object sender, EventArgs e) { lblMessage.Text = string.Empty; if (string.IsNullOrEmpty(txtUserName.Text.Trim()) || string.IsNullOrEmpty(txtPassword.Text)) { lblMessage.Text = "Please fill out both fields!";  }   else if (txtUserName.Text == txtPassword.Text) { lblMessage.Text = "User Name and Password must be different!"; } else if (txtPassword.Text.Length < 6) { lblMessage.Text = "Password can not be shorter than 6 characters!"; txtPassword.Focus();   }  else  {  Result = new AuthenticateUser();  Result.UserName = txtUserName.Text; Result.Password = txtPassword.Text;  this.Close(); } } 

I am trying to make sure that user uses at least 6 characters as a password in my program.

I know how to set maximum size by using MaxLength, but how I do this for the minimum length?

EDIT: How do I check if a string has less or more than 6 characters?

Small bug - when I start typing password I am being presented that password is too short until person entered 6 characters. When 6 or more characters is entered I am showing that password is valid. But, when I type 6 characters, and then remove, the check only react when there is 4 characters. But shouldn't it be tricked when there is less than 6 characters?

protected void KeyDownCheck(object sender, KeyEventArgs e) { bool validPass = txtPassword.Text.Length < 6; if (validPass) lblMessage.Text = "Password can not be shorter than 6 characters!"; else lblMessage.Text = "Password is valid."; } 
added 1114 characters in body
Source Link
HelpNeeder
  • 6.5k
  • 26
  • 95
  • 160
Loading
added 64 characters in body
Source Link
HelpNeeder
  • 6.5k
  • 26
  • 95
  • 160
Loading
edited title
Link
Tad Donaghe
  • 6.6k
  • 1
  • 32
  • 64
Loading
edited title
Link
HelpNeeder
  • 6.5k
  • 26
  • 95
  • 160
Loading
Source Link
HelpNeeder
  • 6.5k
  • 26
  • 95
  • 160
Loading