diff options
author | Gustav Eek <gustaveek@student.gu.se> | 2011-03-12 13:58:51 +0100 |
---|---|---|
committer | Gustav Eek <gustaveek@student.gu.se> | 2011-03-12 13:58:51 +0100 |
commit | ef24b4855b5fa09a5e86a8eb75a3aaf0f1a2822b (patch) | |
tree | b622d9302489cfd7ca2fa0e8a40bea90b795c880 /lib | |
parent | f0743e464bdeeb858dc526a7d5735529f72bd661 (diff) | |
parent | 2b9012f0d2631a6a6705fbe914f6cb8223d3d2e1 (diff) |
Merge branch 'master' of https://github.com/skangas/fripost-tools
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 |