Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
*.out
.DS_Store
screenxtv.conf
screenxtv-gcc-client
22 changes: 22 additions & 0 deletions lib/conf.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include "macros.h"


Expand Down Expand Up @@ -114,3 +115,24 @@ void Config::save(){
#undef pushS
}

// Credit: http://www.gnu.org/software/libc/manual/html_node/getpass.html
size_t my_getpass (char **lineptr, size_t *n, FILE *stream) {
struct termios old, new_t;
int nread;

/* Turn echoing off and fail if we can't. */
if (tcgetattr (fileno (stream), &old) != 0)
return -1;
new_t = old;
new_t.c_lflag &= ~ECHO;
if (tcsetattr (fileno (stream), TCSAFLUSH, &new_t) != 0)
return -1;

/* Read the password. */
nread = getline (lineptr, n, stream);

/* Restore terminal. */
(void) tcsetattr (fileno (stream), TCSAFLUSH, &old);

return nread;
}
13 changes: 11 additions & 2 deletions main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,19 @@ void*loop_fdwrite(void*){
bool auth(Config*config){
char buf[1024];
while(true){
char username[256],password[256];
char username[256];
printf("user name> ");fflush(stdout);
fgets(username,sizeof(username),stdin);
char*usr=trim(username);
if(strlen(usr)==0)return false;

/* Read password without echoing input. */
printf("password> ");fflush(stdout);
fgets(password,sizeof(password),stdin);
char *password = (char *)malloc(256);
size_t n = 256;
my_getpass(&password, &n, stdin);
printf("\n\n");

char*pswd=trim(password);

char key[256],value[256];
Expand All @@ -95,6 +101,9 @@ bool auth(Config*config){
config->put("auth_key",value+1);
return true;
}
else{
printf("Invalid credentials. Please try again.\n");
}
}
}

Expand Down