Replace Password Entry with Asterisks

creating password related program..

Page 1 of 1

8 Replies - 11761 Views - Last Post: 21 January 2010 - 08:16 AM Rate Topic: -----

#1 sweet.k.angel  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 33
  • Joined: 18-January 10

Replace Password Entry with Asterisks

Post icon  Posted 20 January 2010 - 02:59 AM

cin>>pass; //pass is the user entered word

//user entered word it should appear in "*"....

if (pass!=real)
cout<<"wrong password!!";

else
:
:
Is This A Good Question/Topic? 1
  • +

Replies To: Replace Password Entry with Asterisks

#2 ice-t  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 104
  • Joined: 26-May 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 07:03 AM

if u use windows and u have conio library try getpass , it wont show the pass, if u want to make ur own function (still if u use windows) try getch, it will get the ASCII and wont echo on screen then u can echo * and reinterpret the ASCII, of course maybe there are better ways to do it. On *nix i dont know sry
Was This Post Helpful? 0
  • +
  • -

#3 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 07:23 AM

Just iterate through all 'pass' characters using a for loop, and replace every char with a '*'. Example: a[1] = '*', a[2] = '*' .... a[i] = '*'. It's very simple ...

This post has been edited by sarmanu: 20 January 2010 - 07:23 AM

Was This Post Helpful? 0
  • +
  • -

#4 Chaos Mange  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 68
  • Joined: 23-December 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 10:31 AM

Use getch() and if you want to make it so you can hit enter to end it you will need to have it ignored(its character 13 if you are wondering).
Was This Post Helpful? 0
  • +
  • -

#5 taylorc8  Icon User is offline

  • B&

Reputation: 149
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 02:22 PM

heh.. In the Borland Turbo C++ book there's a getche() that may work, get character and echo... But I have done it with getch() and checking for the integer value of 13 in the ascii character. on the visual studio 2010 beta 2 it looks like getche() doesn't have any options for what character to output when it nabs one.


When the user is typing the password I don't think it will show on the screen. That's probably what he/she wants. getch()


puts() is also in there, it lets you type a string and adds the \n to the end...

This post has been edited by taylorc8: 20 January 2010 - 02:29 PM

Was This Post Helpful? 0
  • +
  • -

#6 Chaos Mange  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 68
  • Joined: 23-December 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 03:58 PM

You'll need to have it cout the stars after the getch manually.
Was This Post Helpful? 0
  • +
  • -

#7 khizaraq  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 103
  • Joined: 06-November 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 04:53 PM

I have successfully made such a function which prints Asteriks instead of any input. Backspaces are also handled. In any case as per the rules of dreamincode I cannot hand you the code but I can guide you how I did it:

The basic algo was:

I took an array and put in a password to compare

Then asked the user to enter a password

from the conio.h library you can use the getch() function to take input without the input showing on the output screen.

You can store that input in a temporary variable

Then check to see what that input is

There is another library cctype you can use to check if the entered input is a digit or whatever you can check that here:
http://www.cplusplus...library/cctype/

And well then you can use a couple of if conditions to print whatever you wish a * or & or whatever

Try figuring out the algo for backspaces if you do not get it let me know.
Was This Post Helpful? 2
  • +
  • -

#8 Chaos Mange  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 68
  • Joined: 23-December 09

Re: Replace Password Entry with Asterisks

Posted 20 January 2010 - 05:24 PM

I do actually believe there will be a snippet on it shortly, hopefully.
Was This Post Helpful? 0
  • +
  • -

#9 sweet.k.angel  Icon User is offline

  • New D.I.C Head

Reputation: -5
  • View blog
  • Posts: 33
  • Joined: 18-January 10

Re: Replace Password Entry with Asterisks

Posted 21 January 2010 - 08:16 AM


Thanks a lot to all !!

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1