Page 1 of 1
Field Validation
Posted: Mon Jul 16, 2018 3:57 am
by jwtea
Hello guys , i'm trying to do a field validation.....
The validation consist of
1) Minimum 1 Symbol (eg of symbol "! @ # $ % ^ & *)
2) At least 1 upper case letter
3) Minimum 8 Characters
Thanks!
Re: Field Validation
Posted: Mon Jul 16, 2018 8:33 am
by FourthWorld
Sounds like password strength, yes?
If so, your life as a developer and your users' lives are all easier these days, as best practices for password strength favor length and eschew complexity:
https://www.passwordping.com/surprising ... ines-nist/
If it's for a different problem it would be useful to know so we can help you solve it.
Re: Field Validation
Posted: Mon Jul 16, 2018 8:44 am
by jwtea
Hello FourthWorld
I only want the code for those validation as for my reference guide so i can use it the next time!
Re: Field Validation
Posted: Mon Jul 16, 2018 10:55 am
by jmburnod
Hi jwtea ,
Probably a lot of ways to do this.
Here is one way
Code: Select all
on t_analyse pPW
put "! @ # $ % ^ & *)" into tSymbol
put empty into tSymbolInString
put empty into tUpperL
put the num of chars of pPW into tNbC
repeat for each char tChar in pPW
get offset(tChar,tSymbol)
if it <> 0 then
put it into tSymbolInString
end if
put chartoNum(tChar) into tCN
if tCN > 64 and tCN < 91 then
put tCN into tUpperL
end if
end repeat
put "I need one symbol among " && tSymbol into tSymBolMes
put "I need one upper letter" into tUpperLMes
put "I need minimum 8 characters" into tNbCMes
put empty into tAnswerMes
if tSymbolInString = empty then put tSymBolMes after tAnswerMes
if tUpperL = empty then put cr & tUpperLMes after tAnswerMes
if tNbC < 8 then put cr & tNbCMes after tAnswerMes
filter tAnswerMes without empty
if tAnswerMes <> empty then answer tAnswerMes
else answer "Your PW is nice"
end t_analyse
Best regards
Jean-Marc
Re: Field Validation
Posted: Mon Jul 16, 2018 11:24 am
by mrcoollion
You could use something like this ?
There are probably a lot of faults in this code because I wrote it in 5 minutes in notepad at my office where I do not have LC available.
Code: Select all
put "MyPassw0rd@tH0me" into tPassword
put the length of tPassword into tlengthPassword
Put "QWERTYUIOPASDFGHJKLZXCVBNM" into tUCLetters
Put "1234567890" into tNumbers
Put "!@#$%^&*(){}[]:;<>" into tSymbols
repeat with tCharNumber = 1 to tlengthPassword
put char tCharNumber of tPassword into tCharacter
Switch
Case tUCLetters contains tCharacter
add 1 to tNbrUCChars
break
Case tNumbers contains tCharacter
add 1 to tNbrNumbers
break
Case tSymbols contains tCharacter
Add 1 to tNbrSymbols
break
end switch
end repeat
-- Validation --
If tlengthPassword < 8 then put "Length password must me 8 or longer!" into tMessage
if tMessage is not empty then put CR into tLineBreak
if tNbrUCChars < 1 then put tLineBreak&"Password needs at least one uppercase letter!" after tMessage
if tMessage is not empty then put CR into tLineBreak
if tNbrNumbers < 1 then put tLineBreak&"Password needs at least one number!" after tMessage
if tMessage is not empty then put CR into tLineBreak
if tNbrSymbols < 1 then put tLineBreak&"Password needs at least one of the following symbols !@#$%^&*(){}[]:;<>" after tMessage
-- end validation --
if tMessage is not empty
then
answer tMessage
-- Do what needs to be done if password is not correct
else
answer "Password is ok!"
-- Do what needs to be done if password is correct
end if
Re: Field Validation
Posted: Tue Jul 17, 2018 4:31 am
by jwtea
jmburnod wrote: ↑Mon Jul 16, 2018 10:55 am
Code: Select all
on t_analyse pPW
put "! @ # $ % ^ & *)" into tSymbol
put empty into tSymbolInString
put empty into tUpperL
put the num of chars of pPW into tNbC
repeat for each char tChar in pPW
get offset(tChar,tSymbol)
if it <> 0 then
put it into tSymbolInString
end if
put chartoNum(tChar) into tCN
if tCN > 64 and tCN < 91 then
put tCN into tUpperL
end if
end repeat
put "I need one symbol among " && tSymbol into tSymBolMes
put "I need one upper letter" into tUpperLMes
put "I need minimum 8 characters" into tNbCMes
put empty into tAnswerMes
if tSymbolInString = empty then put tSymBolMes after tAnswerMes
if tUpperL = empty then put cr & tUpperLMes after tAnswerMes
if tNbC < 8 then put cr & tNbCMes after tAnswerMes
filter tAnswerMes without empty
if tAnswerMes <> empty then answer tAnswerMes
else answer "Your PW is nice"
end t_analyse
Best regards
Jean-Marc
Thanks Jean-Marc!!!
It worked perfectly for me!
Re: Field Validation
Posted: Tue Jul 17, 2018 4:35 am
by jwtea
mrcoollion wrote: ↑Mon Jul 16, 2018 11:24 am
Code: Select all
put "MyPassw0rd@tH0me" into tPassword
put the length of tPassword into tlengthPassword
Put "QWERTYUIOPASDFGHJKLZXCVBNM" into tUCLetters
Put "1234567890" into tNumbers
Put "!@#$%^&*(){}[]:;<>" into tSymbols
repeat with tCharNumber = 1 to tlengthPassword
put char tCharNumber of tPassword into tCharacter
Switch
Case tUCLetters contains tCharacter
add 1 to tNbrUCChars
break
Case tNumbers contains tCharacter
add 1 to tNbrNumbers
break
Case tSymbols contains tCharacter
Add 1 to tNbrSymbols
break
end switch
end repeat
-- Validation --
If tlengthPassword < 8 then put "Length password must me 8 or longer!" into tMessage
if tMessage is not empty then put CR into tLineBreak
if tNbrUCChars < 1 then put tLineBreak&"Password needs at least one uppercase letter!" after tMessage
if tMessage is not empty then put CR into tLineBreak
if tNbrNumbers < 1 then put tLineBreak&"Password needs at least one number!" after tMessage
if tMessage is not empty then put CR into tLineBreak
if tNbrSymbols < 1 then put tLineBreak&"Password needs at least one of the following symbols !@#$%^&*(){}[]:;<>" after tMessage
-- end validation --
if tMessage is not empty
then
answer tMessage
-- Do what needs to be done if password is not correct
else
answer "Password is ok!"
-- Do what needs to be done if password is correct
end if
Hello mrcoollion, your code worked too!!! (only the uppercase validation not working but i had fixed it )
Anyway thanks for your time and i definitely learned something new!