954,546 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Regex for password

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 !

matvrix
Newbie Poster
1 post since Jun 2005
Reputation Points: 10
Solved Threads: 0
 

there are several different kinds of regex, is this for a passwd script?

gritty
Newbie Poster
23 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

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.

gritty
Newbie Poster
23 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

I am kind of learning as I go. you are able to test for length of a string using this method

var='abcdef'
echo ${#var}


so this will test for a variable with the lengths inbetween 6 and 11

#!/bin/bash
echo "enter your password"
read PASS
if ((${#PASS} >= 6)) && ((${#PASS} <= 11))
    then echo "password has been accepted"    
fi
shanenin
Posting Whiz in Training
217 posts since May 2005
Reputation Points: 10
Solved Threads: 17
 

this will check if the lenght is between 6 and 11

((${#PASS} >= 6)) && ((${#PASS} <= 11))


this will check if you have at least one lowecase letter

[[ $VAR == *[a-z]* ]]


this will check if you have at least one uppercase letter

[[ $VAR == *[A-Z]* ]]


this will check if you have at least one number

[[ $VAR == *[1-9]* ]]


this will check if you have a letter at the end, either upper or lowercase

[[ $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 :-)

shanenin
Posting Whiz in Training
217 posts since May 2005
Reputation Points: 10
Solved Threads: 17
 

you can use this to check to see if your script has any characters other then numbers or letters

[[ ${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 :-)

shanenin
Posting Whiz in Training
217 posts since May 2005
Reputation Points: 10
Solved Threads: 17
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You