Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Windows programming
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 7-May-13 2:35am
Edited 7-May-13 2:55am
v2
Comments
ThePhantomUpvoter at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.[^].
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thank you both, will try it thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Thank you both, will try it thanks
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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:
#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!
 
Smile | :)
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 6,803
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,421
3 Manas Bhardwaj 4,841
4 Maciej Los 4,330


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 8 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100