password as **** but password will be = "liza"

uhm.... excuse me but can you please help me? i'm having trouble with making password in TURBO c.... the condition goes like this, while the user is entering a password, the user will not see alpha-numeric characters instead, he/ she can see only asterisk... and the computer will read the password.
if the password is 'liza' it will clear the screen and it will loading...if it`s not it will print 'failed to log-in'
can you please tell me the code?????


my only problem is how to asign password and the computer or the program will read the password

here`s my code:

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
44
45
46
47
48
49
50
#include<conio.h>
#include<stdio.h>
main()
{

char *ptr;
char pwd[150];
char c;
int a,x;
int i=0;
char password[15];

      clrscr();

      printf("ENTER PASsword");


while(1)
{

   gets(password);
   x=strcmp(password, "liza");
  c=getch();
if(c==13)
{

pwd[i]=NULL;
break;
}

printf("*");
pwd[i++] = c;
}
   if(x!=0)
   {
	  printf("FAILED TO LOG-IN");
	}

     clrscr();

      for(a=1;a<=80;a++)
    {
    gotoxy(a,1);printf("\xDB");
    gotoxy(a,24);printf("\xDB");
    delay(990);
    gotoxy(37,13);printf("LOADING!!!");
    }

getch();
}


kindly help me..thnx in advance
Last edited on
Hi,liza

I just want to give a simple implement.

char password[10];
char ch;
int i=0;
while( (ch=getch()) != 13) {
password[i]=ch;
i++;
printf("*");
}
To remove the charater echo in the terminal you need to do some special hocus-pocus. Under Linux(and most Unices I would guess) youcan use the termios API to manipulate the terminal I/O. I've written a short example:
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
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

int main(int argc, char *argv[]) {
    char password[11];
    char ch;
    int i = 0;
    struct termios tty_attr;
    int tty_fd = open("/dev/tty", O_RDWR);

    if(tty_fd < 0) {
        fprintf(stderr, "Could not open tty: %s\n",
                strerror(errno));
        return -1;
    }

    tcgetattr(tty_fd, &tty_attr);
    tty_attr.c_lflag &= ~(ICANON|ECHO);
    tcsetattr(tty_fd, TCSANOW, &tty_attr);
    
    memset(password, 0, sizeof(password));

    while( (ch=getc(stdin)) != 10 && i < 10) {
        password[i++]=ch;
        putchar('*');
    }

    printf("\nYou entered %s\n", password);

    tcgetattr(tty_fd, &tty_attr);
    tty_attr.c_lflag |= ICANON|ECHO;
    tcsetattr(tty_fd, TCSANOW, &tty_attr);

    close(tty_fd);    
}


However, if you are working in a Windows environment I have no idea how terminal settings are altered ;-)
He's using Turbo C, which has this functionality built in.
Ouch - Turbo C - duly noted ;-) Thanks.
Don't use turbo C, it's non standard and a very old compiler.
hxslacker ur code is working but can u please give me soe tips or codes that can asign the password as 'liza' and when i click 'delete' or 'space' its shown as asterisk too
You have to check for and respond to specific characters to get different responses.
The following example was written for Win32 API, but you should be able to see how it checks for and responds to 'delete' ('\b') differently than other characters:
http://www.cplusplus.com/forum/general/3570/page1.html#msg15410
Good luck!
do i nid to print this>>>(\b') we are using TURBO C...almost of the codes was not acceptable
my only problem now is =>codes that can asign the password as 'liza' and when i click 'delete' or 'space' its shown as asterisk too<=

i know now how to change the input into asterisk* but i dont knw how to asign a password
in to 'liza'

i dont know if i nid yo use string compare and string copy..
do i nid??

give me some suggestions or tips please..

thnx'
Topic archived. No new replies allowed.