Password cannot contain spaces. Closes #265.

Thanks to Tim Hansen for reporting this bug.
This commit is contained in:
Pierre-Louis Bonicoli 2012-01-07 12:28:47 +01:00
parent df45c4c2d6
commit 2c390390ed
2 changed files with 10 additions and 0 deletions

View File

@ -13,6 +13,8 @@ bipmkpw \- Password hasher for BIP
bipmkpw converts a password into the double-hash used by bip. Copy the bipmkpw converts a password into the double-hash used by bip. Copy the
generated output from bipmkpw into bip config file. generated output from bipmkpw into bip config file.
Password cannot contain spaces.
.SH SEE ALSO .SH SEE ALSO
bip.conf bip.conf

View File

@ -51,11 +51,14 @@ void readpass(char *buffer, int buflen)
write(ttyfd, "Password: ", 10); write(ttyfd, "Password: ", 10);
int idx = 0; int idx = 0;
int valid = 1;
while (idx < buflen) { while (idx < buflen) {
read(ttyfd, buffer+idx, 1); read(ttyfd, buffer+idx, 1);
if (buffer[idx] == '\n') { if (buffer[idx] == '\n') {
buffer[idx] = 0; buffer[idx] = 0;
break; break;
} else if (buffer[idx] == ' ') {
valid = 0;
} }
idx++; idx++;
} }
@ -64,6 +67,11 @@ void readpass(char *buffer, int buflen)
tcsetattr(ttyfd, TCSANOW, &ttback); tcsetattr(ttyfd, TCSANOW, &ttback);
close(ttyfd); close(ttyfd);
if (!valid) {
fprintf(stderr, "Password cannot contain spaces.\n");
exit(1);
}
} }
int main(void) int main(void)