- if ($force) {
- if ($name eq "a-z0-9_-") {
- warn "Please enter a username.\a\n";
- return 0;
- }
- if ($name =~ /[:\n]/) {
- warn "Illegal username, which would break your passwd file.\a\n";
- return 0;
- }
- if ($name !~ /^[a-z0-9_][a-z0-9_\-]*$/) {
- warn "Caution: Username contains illegal characters.\n" .
- "Adding this user may cause utilities " .
- "or applications to malfunction,\n" .
- "or even impose a security risk on your system.\a\n";
+ if ($name eq $usernameregexp) { # user/admin just pressed <Return>
+ warn "Please enter a username\a\n";
+ return 0;
+ } elsif (length($name) > 16) {
+ warn "Username is longer than 16 characters.\a\n";
+ return 0;
+ } elsif ($name =~ /[:\n]/) {
+ warn "Username cannot contain colon or newline characters.\a\n";
+ return 0;
+ } elsif ($name !~ /$usernameregexp/) {
+ if ($usernameregexp eq $defaultusernameregexp) {
+ warn "Illegal username.\n" .
+ "Please use only lowercase Roman, decimal, underscore, " .
+ "or hyphen characters.\n" .
+ "Additionally, a username should not start with a hyphen.\a\n";
+ } else {
+ warn "Username doesn't match the regexp /$usernameregexp/\a\n";