C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old June 17th, 2009, 04:32 PM
raditz raditz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 3 raditz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 14 sec
Reputation Power: 0
General - Preventing program from displaying its password

Hi I am a beginner with C++ and I created a program to convert currency. The problem is that i created it to ask for a password before the program can be run but it shows the password after it is enter. so, when the program is run, it asks for the password and if it is correct it will continue the program but the password remains visible. Is there a way I can prevent this?

Thanks for any help at all.

Reply With Quote
  #2  
Old June 20th, 2009, 02:34 AM
kotarou3 kotarou3 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 4 kotarou3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 sec
Reputation Power: 0
you can use _getch() in a loop from conio.h to not display the password completely or you can use system("cls") for windows or system("clear") for linux using cstdlib

eg1:
Code:
#include <iostream>
#include <conio.h>
#include <string>

int main()
{
	std::string password;
	std::string tmp;
	password.clear();
	char pass;

	std::cout << "Password: ";
	while (pass = _getch())
	{
		if ((pass == 10) || (pass == 13))
			break;
		tmp = pass;
		password.append(tmp);
		tmp.clear();
		
	}

	/*
		password is now the password
	*/
	/*...*/

	return 0;
}


eg2:
Code:
#include <cstdlib>
/*...*/
	system("cls");
/*...*/

Last edited by kotarou3 : June 20th, 2009 at 08:33 AM. Reason: fix

Reply With Quote
  #3  
Old June 20th, 2009, 07:47 AM
raditz raditz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 3 raditz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 14 sec
Reputation Power: 0
Hi thank for the reply. in example 1 they say invalid conversation between char and constant char. The 'password.append(pass);' is the only thing that is highlighted. What does this mean?

Thank You.

Reply With Quote
  #4  
Old June 20th, 2009, 08:32 AM
kotarou3 kotarou3 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 4 kotarou3 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 26 sec
Reputation Power: 0
Whoops, bad code. not even std:: before string. I was in a hurry in the previous post.

Here, code that i tested that it works:
Code:
#include <iostream>
#include <conio.h>
#include <string>

int main()
{
	std::string password;
	std::string tmp;
	password.clear();
	char pass;

	std::cout << "Password: ";
	while (pass = _getch())
	{
		if ((pass == 10) || (pass == 13))
			break;
		tmp = pass;
		password.append(tmp);
		tmp.clear();
		
	}

	/*
		password is now the password
	*/
	/*...*/

	return 0;
}

Reply With Quote
  #5  
Old June 22nd, 2009, 11:30 PM
raditz raditz is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2009
Posts: 3 raditz User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 14 sec
Reputation Power: 0
works

Thanks man system("cls") works good.

Is there way that I can get a GUI for my C++ program? I don't know how to program in GUI.

Thanks

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > General - Preventing program from displaying its password


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
Stay green...Green IT