am a beginner in C++;
am writing a program on C++ and i have bin trying to make a user enter his username and to enter a password and If correct the program will output a message such as: "Welcome Name of User”

If incorrect my program should allow at least one further input of the code word before terminating the process. please how do i go about it. spent all night

Recommended Answers

All 12 Replies

try doing it first by urself. then someone will help u...

you can get the username from the user and then compare it with the username which is in the file or something.(same with the password). to print "welcome user" do the following or something
cout<<"Welcome";
puts(username);

username is the variable having the user's name.

only if u start doing it, someone will help u.. :)

RE: Gel
thanks for the info, this is all i have done. i actually want to add; for instance the user makes a mistake input a wrng username or password, so dat it allows the user retry.

#include "stdafx.h"
#include <iostream>

#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{	
			
	string userName = "";
	string passWord = "";
	
	cout << "Enter your userName: ";
	cin >> userName;
	
	cout << "\n";
	
	cout << "Enter your passWord: ";
	cin >> passWord;
                cout << "\n";
	 
	cout << "Access Granted\n" << " 'Welcome Raymond': ";
	
            return 0;
}

Use a loop to check the data, a while loop should work fine.

on line 21 you need to look up the username in a database and, if found, verify the password.

Put lines 10 thru 21 in a loop so that the program can start all over again if the username and/or password are incorrect (not found in the database)

Note that the database can be as simple as a text file or as complicated as an SQL Server. How you do that part is up to you to decide when you design your program.

RE: AD;
trust me when i say am a beginner. i mean it. seriously am lost, how do i put all that in a loop. please just give me an example, i will be grateful. thank you

Before jumping off the deep end of the pond you first have to learn to swim. read some tutorials about loops and all will become clear to you. Remember, google is your friend.

The following code is a simple example of a for-loop:

for(int i = 0; i < 3; i++)
{
      /* Your code here */
}

This loop repeats the instructions between the '{' '}' 3 times ...

But as Ancient Dragon said, first try searching Google (in future) before you ask a question which you could simply solve yourself ...

much love, i'll do just that. but will keep in touch. thanks

hi fellas, after the much reading and much or little of wat i grasped only could accomplish this;

all i need now is to know how to make the username constant dat if the username is wrongly inpuuted it denies the entry and the same goes for the password. please pips i need help

#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
	string username;
	string raymond ;
	string password1, password2;

	 username = raymond;
	password1 = password2;

	cout << "enter username:";
	cin >> raymond;

	cout <<"\n";

	cout << "enter password:";
	cin >> password1;

	cout <<"\n";
	
	cout << "Please confirm password:";
	cin >> password2;

	if (password1 != password2)
		cout << "Access Denied....";
	
	if (password1 == password2)
		
		cout << "Access Granted....";
		
	return 0;
}

thank you all for your contributions, i need to know how to make numbers appear as asterisks e.g 123456 comes out like (******)

thank you all for your contributions, i need to know how to make numbers appear as asterisks e.g 123456 comes out like (******)

read this thread

please can someone help me. i want too make my password 123456 appear as asterisks as in ******. thanks

#include "stdafx.h"
#include <iostream>
#include <string>

using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{   


    string username;
    string password;


    do {
  cout << "username: ";
  getline(std::cin, username);
  if (username == "Raymond") {
    cout << "password: ";
    getline(std::cin, password);

    if (password != "123456") {

        cout << "invalid password. Please enter valid password." << std::endl;
        cout << "\n";
    }
  } else {
    cout << "invalid username. Please enter valid username." << std::endl;
    cout << "\n";
  }
} while (password != "123456");



    return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.