diff options
author | Stefan Kangas <skangas@skangas.se> | 2011-03-12 13:35:19 +0100 |
---|---|---|
committer | Stefan Kangas <skangas@skangas.se> | 2011-03-12 13:35:19 +0100 |
commit | 2b9012f0d2631a6a6705fbe914f6cb8223d3d2e1 (patch) | |
tree | b5663842d991b68428aaef010a11ef05bf2a6796 /lib | |
parent | df00a5d274e5c06162255ac68b213afe66ec56b0 (diff) |
adduser will not echo the password
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/Fripost/Prompt.pm | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/lib/Fripost/Prompt.pm b/lib/Fripost/Prompt.pm index ad6f1ae..a857cc1 100755 --- a/lib/Fripost/Prompt.pm +++ b/lib/Fripost/Prompt.pm @@ -20,10 +20,19 @@ use String::MkPasswd qw/mkpasswd/; our @EXPORT = qw(prompt_password prompt_username); +sub fix_username { + my ($nam) = @_; + if ($nam !~ /\@/) { + $nam .= '@fripost.org'; + say "Using $nam"; + } + return $nam; +} + sub prompt_password { my $prompt = shift; $prompt //= "Enter new password (blank for random): "; - my $password = prompt $prompt; + my $password = prompt $prompt, -e => '*'; if (!length $password) { $password = mkpasswd( -length => 10, @@ -32,25 +41,30 @@ sub prompt_password { ); say "Generated password: $password"; } - return $password; + return smd5($password); } sub prompt_username { my $prompt = shift; $prompt //= "Enter username: "; - my $username; - while (not defined $username) { - $username = prompt $prompt; - if (!($username =~ /\@/)) { - $username .= '@fripost.org'; - say "Using $username"; - } - if (!Email::Valid->address($username)) { - undef $username; + my $nam; + while (not defined $nam) { + $nam = prompt $prompt; + $nam = fix_username($nam); + if (!Email::Valid->address($nam)) { + undef $nam; say "This is not a valid e-mail address. Try again." } } - return $username; + return $nam; +} + +sub ask_if_ok_or_abort { + my $confirmed = prompt "Is this OK? [no will abort]", -ynt; + unless ($confirmed) { + say "User aborted"; + exit 1; + } } =head1 AUTHOR |