Click to See Complete Forum and Search --> : Stop users from placing spaces in passwords


udsrem
12-13-2002, 02:33 AM
Is there a way to stop some one from entering a password with spaces in it.

I have this code in my signup code.

# except only letters underscores numbers
unless ($u_name =~ /^[A-Z|a-z|0-9]/) {
print "Sorry not a valid Username <br />"; exit; }

# except only letters numbers decimals
unless ($p_word =~ /^[A-Z\a-z\0-9]/) {
print "Sorry not a valid password <br />"; exit; }

but for some reason it still allows spaces.

how can I stop that from happening.

Thanks,

:(

jeffmott
12-13-2002, 07:01 AM
For ^ to mean negation it must be within the character class. Outside of the class it means to match the beginning of a line.

[a-z] # match chars a through z
[^a-z] # match chars except a through z

A character class is a set of characters. In a character class | means a literal vertical line, not OR.

You also want to use if instead of unless. Since you are searching for bad chars you want to say "if $u_name contains a bad character, display error and exit program."

if ($u_name =~ /[^a-zA-Z0-9]/) {
print 'Sorry, not a valid password<br />';
exit 0;
}

Although, personally I think you should allow them to use the space, and at the very least every character available on the keyboard.

udsrem
12-13-2002, 11:22 AM
Thanks Jeff, That's what I thought. I was just unsure about it. and thanks again you are the best.:D