From 0b52f26f90c77da66c2409b32079c9935ab77326 Mon Sep 17 00:00:00 2001 From: Adrian Chiris Date: Sun, 4 Jan 2015 15:30:48 +0200 Subject: [PATCH] ported mft-3.8.0 changes pt2 --- flint/err_msgs.h | 1 + flint/subcommands.cpp | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/flint/err_msgs.h b/flint/err_msgs.h index f6bc9bd..b8c79b1 100644 --- a/flint/err_msgs.h +++ b/flint/err_msgs.h @@ -128,6 +128,7 @@ typedef enum { #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 diff --git a/flint/subcommands.cpp b/flint/subcommands.cpp index be123bb..3495b5b 100644 --- a/flint/subcommands.cpp +++ b/flint/subcommands.cpp @@ -58,6 +58,7 @@ #ifdef __WIN__ #include +#include #endif #include "subcommands.h" @@ -654,7 +655,7 @@ bool SubCommand::getPasswordFromUser(const char *preStr, char buffer[MAX_PASSWOR 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 @@ -668,8 +669,14 @@ bool SubCommand::getPasswordFromUser(const char *preStr, char buffer[MAX_PASSWOR } 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'); @@ -3000,18 +3007,23 @@ bool SetKeySubCommand::verifyParams() 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."); -- 2.46.0