Thread: Login System

  1. #1
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156

    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.

  2. #2
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    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.

  3. #3
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    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.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Then read up about file input and output.

  5. #5
    Student legit's Avatar
    Join Date
    Aug 2008
    Location
    UK -> Newcastle
    Posts
    156
    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.

  6. #6
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    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;
    }
    Last edited by Nor; 11-22-2008 at 09:37 AM.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

  7. #7
    ‡ †hë Ö†hÈr sîÐè ‡ Nor's Avatar
    Join Date
    Nov 2001
    Posts
    299
    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
    Last edited by Nor; 11-22-2008 at 09:43 AM.
    Try to help all less knowledgeable than yourself, within
    the limits provided by time, complexity and tolerance.
    - Nor

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem building Quake source
    By Silvercord in forum Game Programming
    Replies: 16
    Last Post: 07-11-2010, 09:13 AM
  2. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 06:58 AM
  3. Using mscorlib & system namespace in an MFC?
    By Robert_Sitter in forum C++ Programming
    Replies: 3
    Last Post: 11-13-2005, 06:47 PM
  4. Opinions on custom system build
    By lightatdawn in forum Tech Board
    Replies: 2
    Last Post: 10-18-2005, 04:15 AM
  5. system();
    By GanglyLamb in forum C Programming
    Replies: 5
    Last Post: 10-30-2002, 03:57 AM