Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hidepw #6

Merged
merged 3 commits into from Jan 10, 2013
Merged

Hidepw #6

Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -3,3 +3,4 @@
*.out
.DS_Store
screenxtv.conf
screenxtv-gcc-client
@@ -1,6 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <termios.h>
#include "macros.h"


@@ -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 main.cc
@@ -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];
@@ -95,6 +101,9 @@ bool auth(Config*config){
config->put("auth_key",value+1);
return true;
}
else{
printf("Invalid credentials. Please try again.\n");
}
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.