8 Replies - 43197 Views - Last Post: 18 May 2008 - 02:39 PM Rate Topic: -----

#1 adityamolugu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 06

how do i write a password code using C++

Posted 24 June 2006 - 07:41 AM

hi,
iam currently learning c++ in my school,der was a problem given by my teacher to solve, the problem says....
write a program in using c++ which will ask the user the user id and the password.?
my problem is :iam not able to visualise '******" in the password dat will appear in the screen.
plzz help me with dis!!!!
Is This A Good Question/Topic? 0
  • +

Replies To: how do i write a password code using C++

#2 Mrafcho001  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 41
  • View blog
  • Posts: 769
  • Joined: 01-November 05

Re: how do i write a password code using C++

Posted 24 June 2006 - 09:19 AM

For edit boxes in Win32 just add ES_PASSWORD to the Window Style.

for the DOS window... you can use getch(); from the conio.h library. It does not display the character. So you can create a loop that exits when the user pushes enter. And for every keypress that is not the enter key you count << '*';
Was This Post Helpful? 1

#3 adityamolugu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 24-June 06

Re: how do i write a password code using C++

Posted 24 June 2006 - 12:03 PM

View PostMrafcho001, on 24 Jun, 2006 - 08:11 AM, said:

For edit boxes in Win32 just add ES_PASSWORD to the Window Style.

for the DOS window... you can use getch(); from the conio.h library. It does not display the character. So you can create a loop that exits when the user pushes enter. And for every keypress that is not the enter key you count << '*';


thanx a lot 4 ur interest but actually my problem is wenever i am running my program in linux OS iam .....user wen enters his password its not coming in * format. can u help me with dis
i will b very gr8full to u.
Was This Post Helpful? 0
  • +
  • -

#4 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Re: how do i write a password code using C++

Posted 27 June 2006 - 03:18 AM

True....getch() is not supported undeer *NIX systems.
I'm not sure as I'm not near documentation or a compiler right now but I think there's a function called get_password() (or maybe something similar) that accepts the password but does not display an '*' for every character typed.
I'll get back to you in some time.I think I know how this can be done.
Was This Post Helpful? 0
  • +
  • -

#5 yogesh_c2008  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-May 08

Re: how do i write a password code using C++

Posted 02 May 2008 - 08:05 AM

View Postadityamolugu, on 24 Jun, 2006 - 07:41 AM, said:

hi,
iam currently learning c++ in my school,der was a problem given by my teacher to solve, the problem says....
write a program in using c++ which will ask the user the user id and the password.?
my problem is :iam not able to visualise '******" in the password dat will appear in the screen.
plzz help me with dis!!!!

very sorry
if u are getting means send me also
pls regds yogesh
Was This Post Helpful? 0
  • +
  • -

#6 maddy1024  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 02-May 08

Re: how do i write a password code using C++

Posted 02 May 2008 - 08:42 AM

View Postadityamolugu, on 24 Jun, 2006 - 07:41 AM, said:

hi,
iam currently learning c++ in my school,der was a problem given by my teacher to solve, the problem says....
write a program in using c++ which will ask the user the user id and the password.?
my problem is :iam not able to visualise '******" in the password dat will appear in the screen.
plzz help me with dis!!!!

Attached File(s)


Was This Post Helpful? 0
  • +
  • -

#7 perfectly.insane  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 70
  • View blog
  • Posts: 644
  • Joined: 22-March 08

Re: how do i write a password code using C++

Posted 02 May 2008 - 06:23 PM

View Postborn2c0de, on 27 Jun, 2006 - 03:18 AM, said:

True....getch() is not supported undeer *NIX systems.
I'm not sure as I'm not near documentation or a compiler right now but I think there's a function called get_password() (or maybe something similar) that accepts the password but does not display an '*' for every character typed.
I'll get back to you in some time.I think I know how this can be done.


I believe the function that you're referring to is called getpass, which does what you describe (takes in a prompt string as it's first argument though).



If one were to do this manually, one would need to turn off the echo attribute of the console (by using system("stty -echo") or tcgetattr/tcsetattr), then reading the input a character at a time, and reenabling the echo afterwards.
Was This Post Helpful? 0
  • +
  • -

#8 lilseraphin  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 09-May 08

Re: how do i write a password code using C++

Posted 18 May 2008 - 02:17 PM

Guys can somebody answer that question cuz i wanna knw too n i need to use it!!..
here's my email cuz i dont get on dream in code alot send me the name of the library n the explaination of the code
thx guyz..
Was This Post Helpful? 0
  • +
  • -

#9 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1385
  • View blog
  • Posts: 10,962
  • Joined: 06-February 08

Re: how do i write a password code using C++

Posted 18 May 2008 - 02:39 PM

View Postlilseraphin, on 18 May, 2008 - 02:17 PM, said:

Guys can somebody answer that question cuz i wanna knw too n i need to use it!!..
here's my email cuz i dont get on dream in code alot send me the name of the library n the explaination of the code
thx guyz..

1. You didn't actually put your email address.
2. They already answered it. :P
3. This post is two years old
4. I wrote a snippet like this earlier. It hasn't been approved yet, but here's the code:
#include <iostream>
#include <conio.h>
#include <windows.h>

using namespace std;

int main ()
{
    cout << "Enter you password: (max 25 characters)" << endl;
    // password (char array, doesn't work as string)
    char password[25];

    int i = 0; // used to index the current character being read
    while (true) // infinite loop, broken by pressing return
    {
        password[i] = getch(); // get the current character
        cout << "*"; // output a star (can be replaced with a different character)

        if (GetAsyncKeyState(VK_RETURN)) // if return has been pressed
            break; // break from the loop

        i++; // increment our index
    }

    // now fill the rest of the array with '\0' (NULL) character
    for (i; i < strlen(password); i++)
        password[i] = '\0';

    // output the password (just for testing)
    cout << endl << password;
    
    // end of the program
    cout << endl << "Press any key to continue . . .";
    getch ();
}


By the way, it's Windows specific.

NOTE: The only reason you're getting this code for free is that I already wrote it earlier. Generally, we don't give out free code.

This post has been edited by gabehabe: 18 May 2008 - 02:40 PM

Was This Post Helpful? 1

Page 1 of 1