Click here to Skip to main content
15,886,802 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi
I am just starting out with windows programming, i received an exercise to create a windows programme that requests the user to enter a username and password and then validates the password.

Is the only way to do that via a sql file(where the username and password is stored?) I have not started working on sql yet and wonder if i can do storing of the details in the code as well as the validation?

Help will be appreciated, as the responses i get from google all indicate a sql database should be used.

Thanks
C from CT
Posted
Updated 7-May-13 1:55am
v2
Comments
[no name] 7-May-13 7:49am    
Well you do not have to use a database, it makes things easier. You have to store the data somewhere....
C from Cape Town,SA 7-May-13 7:56am    
does it have to be a sql database?

could i do something like this, as I said i havent done Sql as yet
string username;
string password;
do {
std::cout << "username: ";
getline(std::cin, username);
if (username == "Raymond") {
std::cout << "password: ";
getline(std::cin, password);
if (password != "1234") {
std::cout << "invalid password. try again." << std::endl;
}
} else {
std::cout << "invalid username. try again." << std::endl;
}
} while (password != "1234");

i know it wont store anything

The database is not the only place where you may store the password: you may use as well a file. However make sure to store NOT the passwords themselves but their hashes. See the following article OriginalGriff's tip for a guideline: Password Storage: How to do it.[^].
 
Share this answer
 
Thank you both, will try it thanks
 
Share this answer
 
Thank you both, will try it thanks
 
Share this answer
 
No, noooo!

I know that you can do this with the SQL. But you can do evrything in C++!

1. Create a folder called "Login Panel" (I recomend this name)

2. Create 2 files:
username.txt
password.txt
NOTE: The code must be in the same folder!

3. The code:
C++
#include <iostream>
#include <fstream>
using namespace std;

int main () {
  ofstream myfile;
  while(true)
  {
     string password;
     string username;
     cout << "Username: ";cin >> username;
     cout << "Password: ";cin >> password;
 
     myfile.open ("password.txt");
     myfile << password;
     myfile.close();

     myfile.open ("username.txt");
     myfile << username;
     myfile.close();
  }
  return 0;
}</fstream></iostream>


I'd like I was helpful!

:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900