Page 1 of 1

Password policy check VL-WEB

Posted: Thu May 12, 2016 5:49 pm
by avescovi
Hi,

I am developing the authentication for new users.
I want to implement the classical checks:
- Min length 8 characters,
- At least 1 char [a - z]
- At least 1 char [A - Z]
- At least 1 char [0 - 9]
- At least 1 symbol [* -_ ! etc]

There is a way to check automatically these constraints or the way to run a regexp on a string?

Thanks

Andrea

Re: Password policy check VL-WEB

Posted: Fri May 13, 2016 6:40 pm
by Stewart Marshall
Hi Andrea

Below is routine for validating a password along the lines of your requirement (Thanks Danny)

The basic idea is that we loop through the contents on the password on a change of value, and as soon as each requirement is met, a flag is turned on. When all flags are True, the password has passed.

Regards

Code: Select all

Begin_Com Role(*EXTENDS #PRIM_WEB) Height(400) Width(833)
Define_Com Class(#PRIM_VS.Style) Name(#Bad) Borderbottom(1) Borderbrush(#Brush1) Borderleft(1) Borderright(1) Bordertop(1)
Define_Com Class(#PRIM_VS.SolidBrush) Name(#Brush1) Color(255:19:7)

Define_Com Class(#PRIM_VS.Style) Name(#Good) Borderbottom(1) Borderbrush(#Brush2) Borderleft(1) Borderright(1) Bordertop(1)
Define_Com Class(#PRIM_VS.SolidBrush) Name(#Brush2) Color(12:153:4)

Define_Com Class(#xDemoAlpha128.Visual) Name(#gPassword) Displayposition(1) Left(16) Parent(#COM_OWNER) Tabposition(1) Top(16) Width(313) Height(33) Editstyle(#Bad) Caption('Password') Labeltype(Caption)

Evtroutine Handling(#gPassword.Changed)

If (#Com_owner.Validate( #gPassword ))

#gPassword.EditStyle <= #Good
Else
#gPassword.EditStyle <= #Bad
Endif

Endroutine

Mthroutine Name(Validate)
Define_Map For(*Input) Class(#Prim_Alph) Name(#Password)
Define_Map For(*Result) Class(#Prim_boln) Name(#Result)

Define_Com Class(#Prim_boln) Name(#HasUpper)
Define_Com Class(#Prim_boln) Name(#HasLower)
Define_Com Class(#Prim_boln) Name(#HasDigit)
Define_Com Class(#Prim_boln) Name(#HasSymbol)

Define_Com Class(#Prim_alph) Name(#Character)

If (#Password.CurChars >= 8)

Begin_Loop Using(#Std_Num) To(#Password.CurChars)

#Character := #Password.Substring( #Std_Num 1 )

If (#Character.UpperCase.ContainsOnly( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ))
If (#Character.UpperCase = #Character)
#HasUpper := True
Endif

If (#Character.LowerCase = #Character)
#HasLower := True
Endif
Endif

If (#Character.IsNumber)
#HasDigit := True
Endif

If (#Character.Contains( "@" ) *OrIf #Character.Contains( "!" ) OrIf #Character.Contains( "?" ))
#HasSymbol := True
Endif

End_Loop

#Result := (#HasUpper And #HasLower And #HasDigit And #HasSymbol)

Endif

Endroutine

End_Com

Re: Password policy check VL-WEB

Posted: Fri May 13, 2016 7:09 pm
by avescovi
Hi Stewart,

Thank you, from your reply I see that it doesn't exist a way to directly check my constraints with a regular expression.
I will implement something based on your rountine.

have a nice day
Thank you

Andrea

Re: Password policy check VL-WEB

Posted: Fri May 13, 2016 9:33 pm
by Stewart Marshall
If you REALLY want to use a regular expression, you can make a JavaScript Widget to do the job for you.

That said, I personally prefer code that reads like English, in my case, rather than something that looks like gibberish.

Code: Select all

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{4,8}$

Re: Password policy check VL-WEB

Posted: Fri May 13, 2016 9:35 pm
by avescovi
Thanks,
Have a nice day

Andrea