943,965 Members | Top Members by Rank

Ad:
Jun 13th, 2005
0

Regex for password

Expand Post »
It there a way to validate a string that

>> Does not use characters like #$@ in the password.
>> It must contain 1 upper case letter, 1 lower case letter, 1 number & must end in a letter.
>> It must be 6-11 characters

using Regular Exp ?

Any pointer would be greatly apprecaited.

Cheers !
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matvrix is offline Offline
1 posts
since Jun 2005
Jul 22nd, 2005
0

Re: Regex for password

there are several different kinds of regex, is this for a passwd script?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gritty is offline Offline
23 posts
since Jul 2005
Jul 22nd, 2005
0

Re: Regex for password

some pretty standard ones are [A-Z] && [a-z] && [0-9], that should at least get you through the must require cap letters, lowercase letters and a number. The rest will depend on what you are running, such as awk, sed, grep, etc....
Let me know if this helps and what you are running this on and I'll be glad to help ya out.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gritty is offline Offline
23 posts
since Jul 2005
Jul 23rd, 2005
0

Re: Regex for password

I am kind of learning as I go. you are able to test for length of a string using this method
Shell Scripting Syntax (Toggle Plain Text)
  1. var='abcdef'
  2. echo ${#var}

so this will test for a variable with the lengths inbetween 6 and 11
Shell Scripting Syntax (Toggle Plain Text)
  1. #!/bin/bash
  2. echo "enter your password"
  3. read PASS
  4. if ((${#PASS} >= 6)) && ((${#PASS} <= 11))
  5. then echo "password has been accepted"
  6. fi
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Jul 23rd, 2005
0

Re: Regex for password

this will check if the lenght is between 6 and 11
Shell Scripting Syntax (Toggle Plain Text)
  1. ((${#PASS} >= 6)) && ((${#PASS} <= 11))

this will check if you have at least one lowecase letter
Shell Scripting Syntax (Toggle Plain Text)
  1. [[ $VAR == *[a-z]* ]]

this will check if you have at least one uppercase letter
Shell Scripting Syntax (Toggle Plain Text)
  1. [[ $VAR == *[A-Z]* ]]

this will check if you have at least one number
Shell Scripting Syntax (Toggle Plain Text)
  1. [[ $VAR == *[1-9]* ]]

this will check if you have a letter at the end, either upper or lowercase
Shell Scripting Syntax (Toggle Plain Text)
  1. [[ $VAR == *[a-zA-Z] ]]

I am not sure(yet) how to determine if all of the chartacters are iether numbers, or letters, no special character. Example $%&^.

I will let you know what I figure out :-)
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005
Jul 23rd, 2005
0

Re: Regex for password

you can use this to check to see if your script has any characters other then numbers or letters
Shell Scripting Syntax (Toggle Plain Text)
  1. [[ ${VAR} == *[^a-bA-B1-9]* ]]
this will return a 0 if any non letters or numbers are found.

It would be very easy to combine all of these tests into a single script. I learned quite abit myself while looking for this info :-)
Reputation Points: 10
Solved Threads: 17
Posting Whiz in Training
shanenin is offline Offline
217 posts
since May 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: [Bash] problem with script in sed command
Next Thread in Shell Scripting Forum Timeline: help with shell script padding files with spaces





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC