-
Login System
Hello there.
I'm creating a Database for my 6th Form Business, and need a way to write a login system to make it secure from rival Business. Nothing too fancy, it's just a 6th form Business after all :)
Anyways, I have a running database with a few menu's. It's not complete yet, as you can't record data. I havn't gotten round to that yet. But I need a login system, and I have no idea where to start, so thats where you guys come in :P
Can you programmers point me in the direction of a tutorial to help me achieve this?
All help is appreciated.
-
Depends how you want to do it. You could do something as simple as:
Code:
std::string name, pwrd;
std::cout<< "Enter name: ";
std::cin >> name;
std::cout<< "And password: ";
std::cin >> pwrd;
if ( name != "name" && pwrd != "password" ) {
std::cout<< "Login failed.";
return 1;
}
// You're now logged in.
-
That seems pretty simple, thanks!
I will try that one out. But I'm also wondering on a stream based login system. Like writing the Usernames and Passwords to a .txt file and reading them from there.
-
Then read up about file input and output.
-
Thanks, I have, it all looks a wee bit to complicated right now, so i'll get back to it when i've learned more.
-
Here is something from my personal telnet/ftp program.
//user_file.txt
Code:
username:password
fun:in the bright sun
whatDOyouCall:youselfINtheMirror
I've replaced my NetworkClient.send() with std::out so you can compile this.
the return value is 0 if the user fails to loging.
anything else is the User ID to the system.
The format of the User_File.txt determins which user gets what userid.
basicly which line number their user:pass appars on.
Code:
#include <iostream>
#include <fstream>
#include <vector>
struct login{
char name[26], pass[26];
};
int loginuser(std::string filepath){
std::fstream User_File;
std::vector<login> User_List;
User_File.open("user_file.txt", std::ios::in);
if(User_File.is_open()){
login temp;
//populate the user list.
do{
memset(&temp, 0, sizeof(temp));
User_File.getline(&temp.name[0], sizeof(temp.name), ':');
User_File.getline(&temp.pass[0], sizeof(temp.pass));
User_List.push_back(temp);
if(User_File.bad()){
User_List.clear();
throw( std::string("File read error") );
}
if(User_File.eof()){
User_List.pop_back(); //Do this to remove the blank entry at the end of the list.
break;
}
}while(1);
//get the terminal account incormation
std::cout << "Enter your Username: ";
std::cin.getline(&temp.name[0], sizeof(temp.name));
std::cout << "Enter your Password: ";
std::cin.getline(&temp.pass[0], sizeof(temp.pass));
//if the terminal user entered nothing.
if( !strlen(temp.name) || !strlen(temp.pass) ){
std::cout << "User cancled login" << std::endl;
return 0;
}
for(int x = User_List.size();x; x--){
if( strcmp(temp.name, User_List[x-1].name) == 0){
if( strcmp(temp.pass, User_List[x-1].pass) == 0)
return x; //We found a winner
}
}
}else{
throw( std::string("User File could not be opened") );
}
return 0;
}
-
Also to delete a user just put a colon on their login line. and line 36 of the function will take care of it.
Code:
username:password
fun:
whatDOyouCall:youselfINtheMirror