#define FLINT_WB_ERROR "write Block Failed. %s\n"
#define FLINT_NO_ZLIB_ERROR "Executable was compiled with \"dump files\" option disabled.\n"
#define FLINT_FLAG_WITH_FLAG_ERROR "\"%s\" flag must be specified with \"%s\" flag.\n"
+#define FLINT_INVALID_PASSWORD "Invalid Password.\n"
/**************************
* Flint Warning Messages
#ifdef __WIN__
#include <windows.h>
+#include <ctype.h>
#endif
#include "subcommands.h"
return 1;
}
// read chars from stdin and print * to stdout using putchar
- for(i = 0; ; i++) {
+ for(i = 0; ; ) {
status = ReadFile(stdinHndl, &ch, sizeof(char), &numOfBytesRead, NULL);
if (!status || numOfBytesRead != sizeof(char) || ch == '\n' || ch == '\r' || i == (MAX_PASSWORD_LEN -1) ) {
// user finished giving the pw
}
break;
}
- putchar('*');
- buffer[i] = ch;
+ if (isalpha(ch) || isdigit(ch)) {
+ putchar('*');
+ buffer[i++] = ch;
+ } else if (ch == '\b' && i){
+ //delete last astrix and set correct position
+ printf("\b \b");
+ i--;
+ }
}
buffer[i] = '\0';
putchar('\n');
bool SetKeySubCommand::getKeyInteractively()
{
- char keyArr[MAX_PASSWORD_LEN+1];
+ char keyArr[MAX_PASSWORD_LEN+1] = {0};
getPasswordFromUser("Enter Key ", keyArr );
+ if (strlen(keyArr) == 0) {
+ reportErr(true, FLINT_INVALID_PASSWORD);
+ return false;
+ }
+
if (!getGUIDFromStr(keyArr, _userKey,\
"Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) {
- return false;
+ return false;
}
// verify key
hw_key_t verKey;
getPasswordFromUser("Verify Key ", keyArr );
if (!getGUIDFromStr(keyArr, verKey,\
"Invalid Key syntax, it should contain only hexa numbers and of appropriate length.")) {
- return false;
+ return false;
}
if (_userKey.h != verKey.h || _userKey.l != verKey.l) {
reportErr(true, FLINT_SET_KEY_ERROR, "The keys you entered did not match.");