Help please: Validating composition of password

Hello,

How can I check that a password
a) is between 8 to 15 characters
b) contains at least one lowercase letter,
c) contains at least one uppercase letter,
d) contains at least one numeric digit, and
e) contains at least one special character ?

I have this JavaScript but I would like it in Xojo.

function CheckPassword(inputtxt)
{
var decimal= /^(?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
if(inputtxt.value.match(decimal))
{
alert(‘Correct, try another…’)
return true;
}
else
{
alert(‘Wrong…!’)
return false;
}
}

I got it from http://www.w3resource.com/javascript/form/password-validation.php

Thanks.

Lennox

[quote=155789:@Lennox Jacob]var decimal= /^(?=.\d)(?=.[a-z])(?=.[A-Z])(?=.[^a-zA-Z0-9])(?!.*\s).{8,15}$/;
if(inputtxt.value.match(decimal)) [/quote]

This looks fit for a Regex match :
http://documentation.xojo.com/index.php/RegEx

decimal is a search pattern, inputtxt.value is the textfield.text you want to check.

I have a class for this. As I recall, I made it a part of my XDC materials.

Let me know if you want it.

Thanks Ken,

I would appreciate it.

Lennox

No problem (even if you got my name wrong :slight_smile: )

Get it from here:

https://dl.dropboxusercontent.com/u/26920684/M_CheckPassword.zip

As a bonus, it will also let you check variations of the password against the list of 10K most-used passwords. For example, “Y4nk33335” would be flagged because it’s too close to “yankees”.

Thanks Kem,

// Typo … m and n are adjacent on the keyboard.

Lennox

Hi Kem,

Your Class is much more detailed/advanced than I need… Thanks. again.

How can I convert this…
'// Needs uppercase?
'if rules.MinUppercase > 0 then
'criteriaRequested = criteriaRequested + 1

'rx.SearchPattern = “(?-i)([A-Z].*){” + str( rules.MinUppercase ) + “}”
'if rx.Search( pw ) = nil then
'msgList.Append “Insufficient uppercase letters.”
'else
'criteriaCount = criteriaCount + 1
'end if
'end if

to something like this?
Dim MyArray() as string
MyArray = TextField1.Text.Split( “” ) // TextField1.Text is the password

For i = myArray.Ubound DownTo 0 // 0 to UBound(MyArray)
if Val(MyArray(i)) > 64 and Val(MyArray(i)) < 91 then
msgbox "The uppercase character, " + MyArray(i) + “, has been found”
exit
end if
next i

Thanks.

Lennox

Perhaps I misunderstood what you’re trying to do. What you wrote was this:

[quote=155789:@Lennox Jacob]How can I check that a password
a) is between 8 to 15 characters
b) contains at least one lowercase letter,
c) contains at least one uppercase letter,
d) contains at least one numeric digit, and
e) contains at least one special character ?[/quote]

It doesn’t matter how complex the module is, you can use it directly for this purpose. Create a new PasswordRules object, specify your criteria, then use the method in the module to see if the password you’re testing conforms to those rules. Something like this:

  dim rules as new PasswordRules_MTC
  rules.Length = 8
  rules.MinLowercase = 1
  rules.MinUppercase = 1
  rules.MinDigits = 1
  rules.MinOther = 1
  
  dim msg as string
  dim pw as string = TextField1.Text
  if pw.Len <= 15 and M_CheckPassword.Conforms( pw, rules, msg ) then
    MsgBox "It conforms"
  else
    MsgBox msg
  end 

Or are you really looking for something else?

(BTW, I’m not sure why you’d want to limit the length of the password. If they want to write a book as their password, all the better.)

Thanks Kem,

This is exactly what I wanted to do. Works great.

Thanks again.

Lennox