Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
4007CEM/login.cpp
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
81 lines (70 sloc)
2.52 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// login.cpp | |
// BasketBallGame | |
// | |
// Created by Suraj Mann on 21/02/2020. | |
// Copyright © 2020 Suraj Mann. All rights reserved. | |
#include "login.h" | |
#include <iostream> | |
#include <string> | |
using namespace std; | |
// calling login class - Suraj | |
Login::Login() | |
{ | |
} | |
// object method for setting user login details - Suraj | |
void Login::set_user_credentials() | |
{ | |
// function for writing username/password to veactor - Suraj | |
string users_name, users_password; | |
int x=1; | |
while(x>0) | |
{ | |
cout << "Please create a username and password" << std::endl; | |
cout << "Please enter a username: "; | |
cin >> users_name; | |
cout << "Please enter a password: "; | |
cin >> users_password; | |
users_list.push_back(users_name); | |
users_list.push_back(users_password); | |
userName = users_name; | |
password = users_password; | |
// comparing users details against vector for user credentials | |
if(std::find(std::begin(users_list), std::end(users_list), users_name) != std::end(users_list) && std::find(std::begin(users_list), std::end(users_list), users_password) != std::end(users_list) ) | |
{ | |
Login(users_name, users_password); | |
cout << std::endl; | |
cout << "You account has been created successfully!" << std::endl; | |
cout << "Username: " << users_name << std::endl; | |
cout << "Password: " << users_password << std::endl; | |
x=0; | |
} | |
else | |
{ | |
cout << "" << endl; | |
cout << "This username or password is unavailable, please try again!" << std::endl; | |
x=1; | |
} | |
} | |
} | |
// object method for checking user credentials - Suraj | |
void Login::check_user_credentials() | |
{ | |
string users_name, users_password; | |
while(true) | |
{ | |
cout << "" << endl; | |
cout << "Please enter your username and password to login" << endl; | |
cout << "Username: "; cin >> users_name; | |
cout << "Password: "; cin >> users_password; | |
if(std::find(std::begin(users_list), std::end(users_list), users_name) != std::end(users_list) && std::find(std::begin(users_list), std::end(users_list), users_password) != std::end(users_list) ) | |
{ | |
cout << "" << endl; | |
cout << "Welcome " << users_name << " you have successfully logged in!" << endl; | |
} | |
else | |
{ | |
cout << "" << endl; | |
cout << "Your username/password has not been recognised, please try again!" << std::endl; | |
} | |
} | |
} |