Results 1 to 4 of 4
hi
i am facing a situation like this. Its like i am writing a program to insert a user and his password. but i dont want the password to be ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 09-27-2005 #1Linux Newbie
- Join Date
- May 2005
- Location
- Chennai,TamilNadu, India
- Posts
- 141
echo() & noecho()
hi
i am facing a situation like this. Its like i am writing a program to insert a user and his password. but i dont want the password to be echoed on the screen
since i was familiar with ncurses i tried out this logic of using echo() and no echo() commands in the code like this
i added the -lcurses option in the makefileCode:fprintf(handle->outFile,"Enter the password : "); noecho(); fscanf(handle->inFile, "%s",firstpasswd); echo(); fprintf(handle->outFile,"Confirm the password : "); noecho(); fscanf(handle->inFile, "%s",secondpasswd); echo();
But while compiling i got an error such as this,
/usr/data/Common/include/dtype.h:74: error: syntax error before numeric constant
where the code in that include file was like this
I guess this error is because curses has already defined values for false and true, and i am redefining it over here.Code:#ifndef _C_PLUS_PLUS_ #ifdef CORE_TYPES_H #undef false #undef true #endif typedef enum _Bool_E { false = 0,(line no:74) // FALSE = 0, true = 1 // TRUE = 1 } Bool_E; #else typedef enum _Bool_E { FALSE = 0, TRUE = 1 } Bool_E; #endif
I cannot afford to make a change in the .h file since if i do, i will have to change the code at a lot of places ( over a 500 as it is already existing code) which is not possible
Is there any other method i can go about this issue?
Regards
Sharon
- 09-27-2005 #2Linux Newbie
- Join Date
- May 2005
- Location
- Chennai,TamilNadu, India
- Posts
- 141
i solved the problem by working it out another way. but i think it is a roundabout way. but it is ok for now
I wrote a function called getpasswd(char * passwd)
and i just called this from where i wanted to get the password.Code:int getpasswd(char* passwd) { int i=0; int g=0; char password[64]; struct termios org_opts, new_opts; int res=0; while(i<64) { //----- store old settings ----------- res=tcgetattr(STDIN_FILENO, &org_opts); assert(res==0); //---- set new terminal parms -------- memcpy(&new_opts, &org_opts, sizeof(new_opts)); new_opts.c_lflag &= ~(ICANON | ECHO | ECHOE | ECHOK | ECHONL | ECHOPRT | ECHOKE | ICRNL); tcsetattr(STDIN_FILENO, TCSANOW, &new_opts); g=getchar(); //------ restore old settings --------- res=tcsetattr(STDIN_FILENO, TCSANOW, &org_opts); assert(res==0); if(g!='\n' && g !='\r') { password[i]=g; i++; } else { break; } } password[i]='\0'; strcpy(passwd,password); return 0; }
Instead i usedfscanf(handle->inFile, "%s",firstpasswd);
if anyone knows of a better way to do this please let me know.Code:fprintf(handle->outFile,"Enter the password : "); getpasswd(firstpasswd); fprintf(handle->outFile,"\nConfirm the password : "); getpasswd(secondpasswd);
ok
- 09-27-2005 #3Linux Newbie
- Join Date
- Oct 2004
- Posts
- 158
Gee. You went to a lot of work - getpass() in unistd.h is part of the standard library. It supresses echoing on a variety of terminal types.
- 09-27-2005 #4Linux Newbie
- Join Date
- May 2005
- Location
- Chennai,TamilNadu, India
- Posts
- 141
cool jim,
i did not know about that function, anyway now i know thanks to u.
Will implement that and see. since i read the man page and seems it will work for my program
thanks


Reply With Quote
