Field Validation
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Field Validation
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!
The validation consist of
1) Minimum 1 Symbol (eg of symbol "! @ # $ % ^ & *)
2) At least 1 upper case letter
3) Minimum 8 Characters
Thanks!
-
- VIP Livecode Opensource Backer
- Posts: 9838
- Joined: Sat Apr 08, 2006 7:05 am
- Location: Los Angeles
- Contact:
Re: Field Validation
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.
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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Field Validation
Hello FourthWorld
I only want the code for those validation as for my reference guide so i can use it the next time!
I only want the code for those validation as for my reference guide so i can use it the next time!
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Field Validation
Hi jwtea ,
Probably a lot of ways to do this.
Here is one way
Best regards
Jean-Marc
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
Jean-Marc
https://alternatic.ch
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands
Re: Field Validation
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.
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
jmburnod wrote: ↑Mon Jul 16, 2018 10:55 amBest regardsCode: 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
Jean-Marc
Thanks Jean-Marc!!!
It worked perfectly for me!
Re: Field Validation
Hello mrcoollion, your code worked too!!! (only the uppercase validation not working but i had fixed it )mrcoollion wrote: ↑Mon Jul 16, 2018 11:24 amCode: 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
Anyway thanks for your time and i definitely learned something new!