-
Notifications
You must be signed in to change notification settings - Fork 0
/
testpass.c
43 lines (36 loc) · 920 Bytes
/
testpass.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* testpass.c
*/
#include <stdio.h>
#include <string.h>
#include "readsecret.h"
int main( int argc, char** argv )
{
unsigned char pw[ 16 ];
int rc;
int i;
struct timespec idle_timer;
struct timespec* idle_timer_ptr = NULL;
memset(pw, 0xfe, sizeof(pw));
if( argc > 1 && strcmp(argv[1],"-t")==0 ) {
idle_timer.tv_sec = 10;
idle_timer.tv_nsec = 0;
idle_timer_ptr = & idle_timer;
}
rc = rsecret_get_secret_from_tty_timed(
pw, sizeof(pw)-1,
"Password: ",
idle_timer_ptr );
if( rc == 0 ) {
printf("Pass was %d characters = [%s]\n", strlen(pw), pw );
}
else {
printf("\nFailed to read password (rc=%d): %s\n",
rc, rsecret_strerror(rc) );
}
printf("Password buffer is:\n");
for( i=0; i < sizeof(pw)/2; ++i ) {
printf(" pw[%2d] = %02x pw[%2d] = %02x\n",
i, pw[i], i+sizeof(pw)/2, pw[i+sizeof(pw)/2] );
}
return rc;
}