Field Validation

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Field Validation

Post by jwtea » Mon Jul 16, 2018 3:57 am

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!

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9801
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Field Validation

Post by FourthWorld » Mon Jul 16, 2018 8:33 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: Field Validation

Post by jwtea » Mon Jul 16, 2018 8:44 am

Hello FourthWorld :D

I only want the code for those validation as for my reference guide so i can use it the next time!

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2718
Joined: Sat Dec 22, 2007 5:35 pm
Location: Genève
Contact:

Re: Field Validation

Post by jmburnod » Mon Jul 16, 2018 10:55 am

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
https://alternatic.ch

mrcoollion
Posts: 709
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: Field Validation

Post by mrcoollion » Mon Jul 16, 2018 11:24 am

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

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: Field Validation

Post by jwtea » Tue Jul 17, 2018 4:31 am

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!!! :lol:
It worked perfectly for me!

jwtea
Posts: 66
Joined: Fri Mar 23, 2018 2:01 am

Re: Field Validation

Post by jwtea » Tue Jul 17, 2018 4:35 am

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! :D

Post Reply

Return to “Talking LiveCode”