Loading
October 02, 2014, 12:23:10 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Welcome!
 
   Forum Home   Help Search Forum Login Register  
Pages: [1]   Go Down
  Send this topic  |  Print  
Author Topic: Password  (Read 741 times)
aanthonyz
Newbie
*
Posts: 13


« on: September 22, 2009, 04:00:26 PM »

I wanna create a password for my code so when you type it you keep going and if its wrong it says "incorrect". I wanna do this for three thing...
Code:
#include <iostream>
#include <windows.h>
#include <string>


using namespace std;

int main(void) {

cout << "Loading..." << endl;
Sleep(3000);
string password;
cout << "Please enter Primary password" << endl;
getline (cin, password);

if(password == "1")
{
string answer;
system("CLS");
}
cout << "Checking... " << endl;
Sleep(2000);
cout << "Please enter secondary password..." << endl;
getline (cin, password);
Code:
if(password == "2")
{
string answer;
system("CLS");
}
cout << "Password Accepted!" << endl;
Sleep(5000);
}
Code:
if(password == "1234")
{
string answer;
system("CLS");
}
cout << " Nice job getting this far..." << endl;
Sleep(2000);
cout << " One more thing before opening..." << endl;
Sleep(2000);
cout << " Que es el nombre de mi perro? " << endl;
getline (cin, password);

if(password == "shadow")
{
string answer;
system("CLS");
}
cout << " Only one person should have gotten this far... " << endl;
Sleep(2000);


All help would be appreciated
Logged
Nubtruck
Newbie
*
Posts: 40



« Reply #1 on: September 26, 2009, 01:00:27 PM »

You could "#include <string>" and use the function "strcmp();" For example:

Code:
# include <iostream>
# include <string>

int main () {

char str1[5] = {'p', 'a', 's', 's'};
char str2[5];

std::cout << "Enter password: ";
std::cin >> str2;

if (strcmp(str1,str2)==0) {
std::cout << "Welcome user..." << "\n\n";
} else {
std::cout << "Intruder alert!" << "\n\n";
}

return 0;
}

"strcmp(str1,str2); tests the strings for equality. It returns a negative number if str1 is less than str2, or returns zero if the two strings are equal, also it returns a positive number if str1 is greater than str2" -
« Last Edit: September 05, 2010, 01:53:56 AM by bluetoo » Logged

Code:
Practice();
void Learn() { Practice(); }
void Practice() { Learn(); }
Pages: [1]   Go Up
  Send this topic  |  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!