6 Replies - 2316 Views - Last Post: 17 February 2010 - 09:07 PM Rate Topic: -----

#1 Guest_vongola*


Reputation:

password masking for c++

Posted 17 February 2010 - 02:58 PM

hi.. i want to know the program for pssword masking using c++ language.. i want to show the program of this output..

Username: dastuc
Password: advancec
**take note.. i want my password to be secured.. so.. the output for password should be
Password: *******

.. thanks a lot :D
Is This A Good Question/Topic? 0

Replies To: password masking for c++

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 5954
  • View blog
  • Posts: 23,215
  • Joined: 23-August 08

Re: password masking for c++

Posted 17 February 2010 - 03:09 PM

There's no portable way to do this. What is your compiler and development environment.
Was This Post Helpful? 0
  • +
  • -

#3 taylorc8  Icon User is offline

  • B&

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

Re: password masking for c++

Posted 17 February 2010 - 06:17 PM

I don't think that can be done with C++, I've never seen C++ used for doing it. Try writing the code in Java, k? Thanks, bye.
Was This Post Helpful? -1
  • +
  • -

#4 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: password masking for c++

Posted 17 February 2010 - 06:45 PM

@taylor, why wouldn't it be possible. its c++ :)

like jack said its certainly not cross platform compatible because you need to use getch() (or some other way to get key press) but getch() is located in conio.h.

#include <conio.h> //need this

string enter_password(void)
{
	string password;
	password.resize(100);
	for(int i=0; i<100; i++)
	{
		char c = getch();
		if(c == 0x0D)
			break;
		password[i] = c;
		cout<<'*';
	}
	cout<<endl;
	return password;
}


This post has been edited by ImaSexy: 17 February 2010 - 06:45 PM

Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5642
  • View blog
  • Posts: 12,359
  • Joined: 16-October 07

Re: password masking for c++

Posted 17 February 2010 - 08:15 PM

#include <conio.h> //need this



"This" is non standard, non portable, and non C++. It is like C code herpes.

If you're using a GNU compiler, you can use getpass. Also non standard, but at least it's portable and maybe even updated this century.

Standard C++ IO is stream based. Streams are device agnostic to some extent; they can be files, keyboard entry, memory buffers, whatever. As such, standard IO doesn't do a lot of fancy console stuff.
Was This Post Helpful? 0
  • +
  • -

#6 jjl  Icon User is offline

  • Engineer
  • member icon

Reputation: 1046
  • View blog
  • Posts: 4,449
  • Joined: 09-June 09

Re: password masking for c++

Posted 17 February 2010 - 08:42 PM

Quote

"This" is non standard, non portable, and non C++. It is like C code herpes.

nice analogy lol I dont know any other way of doing a text masking, besides using getch()
Was This Post Helpful? 0
  • +
  • -

#7 no2pencil  Icon User is online

  • Head MFIC
  • member icon

Reputation: 5066
  • View blog
  • Posts: 26,448
  • Joined: 10-May 07

Re: password masking for c++

Posted 17 February 2010 - 09:07 PM

printf("\b");


Or you can put the keyboard into non buffered mode.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1