X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2Flogin_src%2Fmain.c;h=bc9013d42823c2d21040493d6ef623677fd0b96f;hb=4c78a1bdd506cda6cda27ee342165c7dfa7ecdc2;hp=59b4a784d5bab9d047f3864a267d2ad20efc7aa6;hpb=a41c4af4ae30e963f6bc370efad60dacc39b0275;p=tpg%2Facess2.git diff --git a/Usermode/Applications/login_src/main.c b/Usermode/Applications/login_src/main.c index 59b4a784..bc9013d4 100644 --- a/Usermode/Applications/login_src/main.c +++ b/Usermode/Applications/login_src/main.c @@ -27,10 +27,13 @@ int main(int argc, char *argv[]) for(;;) { sUsername = GetUsername(); + if(!sUsername) continue; sPassword = GetPassword(); + if(!sPassword) continue; if( (uid = ValidateUser(sUsername, sPassword)) == -1 ) { printf("\nInvalid username or password\n"); + _SysDebug("Auth failure: '%s':'%s'", sUsername, sPassword); free(sUsername); free(sPassword); } @@ -61,36 +64,42 @@ int main(int argc, char *argv[]) return 0; } -/** - * \fn char *GetUsername() - */ -char *GetUsername() +char *_GetString(int bEcho) { - char ret[BUFLEN] = {0}; + char ret[BUFLEN]; int pos = 0; char ch; - // Prompt the user - printf("Username: "); - // Read in text while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) { + // Handle backspace if(ch == '\b') { if( pos <= 0 ) continue; pos --; ret[pos] = '\0'; } + // Ctrl-C : Cancel + else if( ch == 'c'-'a'+1) + pos = 0; + // Ctrl-U : Clear + else if( ch == 'u'-'a'+1) + pos = 0; + // Ignore \r + else if( ch == '\r' ) + continue; else ret[pos++] = ch; - // Echo out to the screen - fputc(ch, stdout); + // Don't echo out to the screen + if( bEcho ) { + fputc(ch, stdout); + fflush(stdout); + } if(pos == BUFLEN-1) break; } - // Finish String ret[pos] = '\0'; printf("\n"); @@ -98,36 +107,29 @@ char *GetUsername() } /** - * \fn char *GetPassword() + * \fn char *GetUsername() */ -char *GetPassword() +char *GetUsername() { - char ret[BUFLEN]; + char ret[BUFLEN] = {0}; int pos = 0; char ch; // Prompt the user - printf("Password: "); - - // Read in text - while( (ch = fgetc(stdin)) != -1 && ch != '\n' ) - { - if(ch == '\b') { - if( pos <= 0 ) continue; - pos --; - ret[pos] = '\0'; - } - else - ret[pos++] = ch; - - // Don't echo out to the screen - //fputc(stdout, ch); - - if(pos == BUFLEN-1) break; - } + printf("Username: "); + fflush(stdout); - ret[pos] = '\0'; + return _GetString(1); +} + +/** + * \fn char *GetPassword() + */ +char *GetPassword() +{ + // Prompt the user + printf("Password: "); + fflush(stdout); - printf("\n"); - return strdup(ret); + return _GetString(0); }