Make repeating password optional with -r

This is useful when creating a new password, but annoying when just
using it to calculate the password to log in.
This commit is contained in:
Jonathan Schleifer 2014-09-22 21:00:50 +02:00
parent 56848a00a1
commit 9e363e9311

10
main.c
View file

@ -43,7 +43,7 @@ usage(void)
fprintf(stderr, fprintf(stderr,
"Usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-n] [-o MAXOPS] [-k KEYFILE]\n"); "Usage: scrypt-genpass [-l LEN] [-m MAXMEM] [-n] [-o MAXOPS] [-k KEYFILE]\n");
fprintf(stderr, fprintf(stderr,
" [-p PASS] <site>\n"); " [-p PASS] [-r] [-v] <site>\n");
fprintf(stderr, fprintf(stderr,
" scrypt-genpass -t\n"); " scrypt-genpass -t\n");
fprintf(stderr, fprintf(stderr,
@ -92,6 +92,7 @@ main(int argc, char *argv[])
char ch; char ch;
int rc; int rc;
bool repeat = false;
#ifdef NEED_WARN_PROGNAME #ifdef NEED_WARN_PROGNAME
warn_progname = "scrypt-genpass"; warn_progname = "scrypt-genpass";
@ -102,7 +103,7 @@ main(int argc, char *argv[])
init_parms(&sg_parms); init_parms(&sg_parms);
/* Parse arguments. */ /* Parse arguments. */
while ((ch = getopt(argc, argv, "htk:l:m:no:p:v")) != -1) { while ((ch = getopt(argc, argv, "htk:l:m:no:p:rv")) != -1) {
switch (ch) { switch (ch) {
case 'k': case 'k':
sg_parms.keyfile = strdup(optarg); sg_parms.keyfile = strdup(optarg);
@ -125,6 +126,9 @@ main(int argc, char *argv[])
case 't': case 't':
unit_tests(); unit_tests();
break; break;
case 'r':
repeat = true;
break;
case 'v': case 'v':
sg_parms.verbose = 1; sg_parms.verbose = 1;
break; break;
@ -142,7 +146,7 @@ main(int argc, char *argv[])
if (!sg_parms.passwd) { if (!sg_parms.passwd) {
/* Prompt for a password. */ /* Prompt for a password. */
if (tarsnap_readpass((char**)&(sg_parms.passwd), "Please enter passphrase", if (tarsnap_readpass((char**)&(sg_parms.passwd), "Please enter passphrase",
"Please confirm passphrase", 1)) (repeat ? "Please repeat passphrase" : NULL), 1))
exit(1); exit(1);
} }
sg_parms.passwdlen = strlen(sg_parms.passwd); sg_parms.passwdlen = strlen(sg_parms.passwd);