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?
if (passwordTextBox.Text.Length < 6)
{
MessageBox.Show("Passwords must be at least 6 characters long.");
return /*false*/;
}
// Do some stuff...
return /*true*/;
If you are going to have multiple user interfaces where the user can enter their password (web, mobile, windows client, etc) or would provide a service for doing the same (web, wcf, etc), then I think your best option is to catch this type of error at the most common level to all of these platforms.
We generally implement business rules like this in the database (through stored procedures) so that we have one well-known location to check and change these rules.
If you are using a database that doesn't support stored procedures, then you could implement this functionality in the "business layer", or the set of code responsible for performing the business logic for your application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With