User password restriction to alphanumerical chars only

   —   
This article shows you how to restrict the user password only to characters and numbers.
You will need to open /CMSWebparts/Membership/RegistrationForm.ascx.cs file and add following code into beggining of btnOK_Click method:

// Custom code for restrict password to alphanumerical chars only

string Password = txtPassword.Text;
int PswLength = txtPassword.Text.Length;
int j;
bool ContinueRegistration = true;

for (j = 1; j < PswLength; j++)
{
   if ((Char.IsNumber(Password, j) == false) && (Char.IsLetter(Password, j) == false))
   {
       lblError.Text = "Your custom message (E.g. \"Password must be alphanumeric only!\")";
       ContinueRegistration = false;
   }

}

if (ContinueRegistration)

//There will be rest of default code as it is now…



See also:


Applies to: Kentico CMS 3.1a
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.