We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,621 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

getch() replacement

This is a simple password implementation.

void getPassword()
{
     int i = 0, flag = 0 ;
     char c ;

     char password[100] ;

     cout<<"\n Enter Password : " ;

     while(1)
     {
        c = getch() ;

        if(c! = 13 && c! = 8)
        {
         cout<<"*" ;

         Password[i] = c ;

         i++ ;
        }

        else if(c == 8 && i)
        {
           Password[--i] = '\0' ;

           cout<<"\b \b" ;
        }

        if(c == 13)
        {
         Password[i] = '\0' ;

         break ;
        }

      }


}

Here I'm using getch() method and conio.h for accepting a key board hit without echo-ing it.
My question is, what is its replacement in other compilers, especially in Linux OS ?

I saw ncurses library but couldn't find any method that works like getch().

3
Contributors
2
Replies
7 Hours
Discussion Span
8 Months Ago
Last Updated
3
Views
np complete
Posting Whiz
385 posts since Sep 2010
Reputation Points: 18
Solved Threads: 36
Skill Endorsements: 0

With 10 pages of posts here on DaniWeb alone, I'm sure you can find the answer using SEARCH.

WaltP
Posting Sage w/ dash of thyme
Team Colleague
11,404 posts since May 2006
Reputation Points: 3,421
Solved Threads: 1,055
Skill Endorsements: 36

For linux you could get around using ncurses by using something such as:

http://www.daniweb.com/software-development/c/threads/77633/masking-user-input-password

but there is no standard way of doing this.

And the preferred way for a windows terminal program would be to use windows functions instead of conio.h, but I guess it doesn't matter.

iamthwee
Posting Genius
6,254 posts since Aug 2005
Reputation Points: 1,567
Solved Threads: 476
Skill Endorsements: 33

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0952 seconds using 2.69MB