mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-27 12:05:15 +00:00
#44 hide password input
This commit is contained in:
parent
4ee39714a7
commit
209c4a37c0
18
src/common.c
18
src/common.c
@ -28,7 +28,8 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#ifdef WINDOWS32
|
#ifdef WINDOWS32
|
||||||
#include <winsock.h>
|
#include <winsock2.h>
|
||||||
|
#include <conio.h>
|
||||||
#else
|
#else
|
||||||
#include <arpa/nameser.h>
|
#include <arpa/nameser.h>
|
||||||
#ifdef DARWIN
|
#ifdef DARWIN
|
||||||
@ -183,11 +184,26 @@ read_password(char *buf, size_t len)
|
|||||||
|
|
||||||
tp.c_lflag &= (~ECHO);
|
tp.c_lflag &= (~ECHO);
|
||||||
tcsetattr(0, TCSANOW, &tp);
|
tcsetattr(0, TCSANOW, &tp);
|
||||||
|
#else
|
||||||
|
int i;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
printf("Enter password: ");
|
printf("Enter password: ");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
#ifndef WINDOWS32
|
||||||
scanf("%79s", pwd);
|
scanf("%79s", pwd);
|
||||||
|
#else
|
||||||
|
for (i = 0; i < sizeof(pwd); i++) {
|
||||||
|
pwd[i] = getch();
|
||||||
|
if (pwd[i] == '\r' || pwd[i] == '\n') {
|
||||||
|
pwd[i] = 0;
|
||||||
|
break;
|
||||||
|
} else if (pwd[i] == '\b') {
|
||||||
|
i--; /* Remove the \b char */
|
||||||
|
if (i >=0) i--; /* If not first char, remove one more */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
#ifndef WINDOWS32
|
#ifndef WINDOWS32
|
||||||
|
Loading…
Reference in New Issue
Block a user