473,406 Members | 2,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Portable password on console

180 100+
How can I create a C++ Console application, compiled with GCC, portable to Linux and Windows, with a password prompt without echo (does not show the password as you type it)?

I would like something like those:
- with stars echo:

User: bob
Password: ******

- or without any echo at all

User: bob
Password:

I googled this for hours without finding any solution that were a Console application (usable with bash, dos, etc) compiled with GCC and portable to Windows and Linux.
Mar 2 '07 #1
8 3677
You can implement your own logic....

using the do while loop read a character by character using getch() and print * once after reading one caharcter till user press enter key ascii value of enter is 0x13..
using string concatenation you can get the whole string.....

Better check our old threads we solved one issue regarding the same....




Regards
Rajesh
<email deleted>
Mar 2 '07 #2
vermarajeev
180 100+
You can implement your own logic....

using the do while loop read a character by character using getch() and print * once after reading one caharcter till user press enter key ascii value of enter is 0x13..
using string concatenation you can get the whole string.....

Better check our old threads we solved one issue regarding the same....




Regards
Rajesh
This is what you are talking about;

Expand|Select|Wrap|Line Numbers
  1. string password;
  2. char ch;
  3. while( (ch=getch()) != '\r' )
  4. {
  5.    cout<<"*";
  6.    password.push_back(ch);
I know that solution. but what if the user hits a backspace or delets a character
And another thing is getch() is not recoznized on linux....

Help
Mar 2 '07 #3
DeMan
1,806 1GB
Why would a user hit backspace during a password, don't they know it? They already get three bites at the cherry (usually).

Seriously, I have used some very UNFORGIVING machines (for some reason mainly on UNIX, but this might show I just don't understand it) wher backspaces add characters, so you have to use del, but del only works if you press it exactly enough times (and being a password, you asometimes don't know how many wrong characters you added because it doesn't even show a mask). This is when you focus on managing to hit the right keys at leats once on your three efforts.....
Mar 2 '07 #4
Banfa
9,065 Expert Mod 8TB
I do not believe there is any standard way to get input from the console without echoing it because that is how the console works.

I think ryou only option will be to use non-standard for the input.

By best(well only) suggestion is to split all the non-standard code into a separate code file that makes a set interface available to the rest of the program. Then hopefully you will be able to port you program to different platforms by making changes to the (hopefully) small code file containing the non-standard code.
Mar 2 '07 #5
vermarajeev
180 100+
I do not believe there is any standard way to get input from the console without echoing it because that is how the console works.

I think ryou only option will be to use non-standard for the input.

By best(well only) suggestion is to split all the non-standard code into a separate code file that makes a set interface available to the rest of the program. Then hopefully you will be able to port you program to different platforms by making changes to the (hopefully) small code file containing the non-standard code.
Hi Banfa,
I was just waiting for you to reply. I have not seen you posting replies to questions frequently as you did before.

I got getpass(S) method on linux. Here is the link
http://docsrv.sco.com:507/en/man/html.S/getpass.S.html

Can you suggest something like this
Mar 3 '07 #6
i think we can do by this or use non canonical format

#include <unistd.h>
#include <string.h>
#include <termios.h>



printf("Enter Your PassWord : ");
getpass(passwd);
Mar 3 '07 #7
Banfa
9,065 Expert Mod 8TB
Hi Banfa,
I was just waiting for you to reply. I have not seen you posting replies to questions frequently as you did before.

I got getpass(S) method on linux. Here is the link
http://docsrv.sco.com:507/en/man/html.S/getpass.S.html

Can you suggest something like this
As far as I am aware nothing like this getpass exists on the Windows platform.

However you could implement a similar function with the same name using getch() from conio.h in a separate file. Then the only difference between a WIndows and Unix build would be the inclusion (smallish) of an extra source file.

Well I spend a fair bit on time on Admin duties now and there are many other C/C++ mods so I don't attempt to answer as much now. I tend to cherry pick the interesting or simple problems.
Mar 3 '07 #8
Banfa
9,065 Expert Mod 8TB
i think we can do by this or use non canonical format

#include <unistd.h>
#include <string.h>
#include <termios.h>



printf("Enter Your PassWord : ");
getpass(passwd);
unistd.h and termios.h and not standard headers and therefore could not feature in a portable solution.
Mar 3 '07 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Yang | last post by:
Hi Is it possible to mask console input in a c# console application? What I mean is: if I entered string "test" in the console, it'll echo "****"(or nothing) instead of the string "test". I've...
1
by: Nitin | last post by:
I have created a console based application using C# which asks for the user identification to work using that system. Now, the problem is that i'm not able to hide or encrypt the password on the...
2
by: Phil Townsend | last post by:
I have been asked to rewrite some apps that contain databases of username and passwords to store the passwords as hashes. Getting the data into a hash format is no problem. however, how do I go...
3
by: Roy Gourgi | last post by:
HI, Why is this password authentication not working as I am sending? I am trying to change the password and yet it is not working. What am I doing wrong? TIA Roy
2
by: SharpCoderMP | last post by:
hi, i'm writing a console application and i would like to be able to safely retrive password from the user, so noone can see how it is being typed. consider this scenario: Console.Write("Enter...
5
by: Richard Giuly | last post by:
Hello, I would like to write "portable" C++ code that could theoretically run on linux, windows, and other platforms, and I'd like to use VS as the editor/compiler/linker. The simplest thing...
3
by: julianmoors | last post by:
Hey, Currently I'm writing a VB.NET/1.1 app and I need to mask the input for the password field. Does anyone know how to do this in VB? I've seen a C# example, but wouldn't know how to convert...
5
by: per9000 | last post by:
Hi all, I want to create an encryption program and started thinking about not storing sensitive information in the memory since I guess someone might steal my computer an scan my memory. So I...
5
by: jehugaleahsa | last post by:
Hello: We have a request for an console application to change the administrative password on our user's machines during an upcoming update. The console application will be called from a batch...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.