Selaa lähdekoodia

universal place holder, segmentation error remains,

- Place holders are now universalized with password & password2
- Unneeded variables removed (counter, x, pswd)
- Fixed quit() improper ofstream behavior
- Implemented while (!.empty()) instead of for loop
Fixing-travis-yml
BinHong Lee 8 vuotta sitten
vanhempi
commit
a419dbed0a
3 muutettua tiedostoa jossa 26 lisäystä ja 23 poistoa
  1. +23
    -21
      LogInSystem.cpp
  2. +1
    -1
      Person.cpp
  3. +2
    -1
      database.txt

+ 23
- 21
LogInSystem.cpp Näytä tiedosto

@@ -1,6 +1,6 @@
/* /*
* Written by : BinHong Lee * Written by : BinHong Lee
* Last edited : 4/12/2016
* Last edited : 5/12/2016
*/ */


#include <iostream> #include <iostream>
@@ -10,8 +10,10 @@
#include "Person.cpp" #include "Person.cpp"
using namespace std; using namespace std;


int getUsernameCounter(string, int);
//Declaration of functions
void getUser(string);
void login(); void login();
void adminLogin();
void loggedIn(); void loggedIn();
void registration(); void registration();
void editCredentials(); void editCredentials();
@@ -22,14 +24,16 @@ void chgEmail();
void chgPhoneNo(); void chgPhoneNo();
void quit(); void quit();


//Stacks to store the data
stack<Person> users; stack<Person> users;

//Declaration of place holding variables
Person currentUser; Person currentUser;
string username; string username;
string password; string password;
string password2;
string email; string email;
string phoneNo; string phoneNo;
int counter;
int x = 0;
int wrongPass = 0; int wrongPass = 0;


int main() int main()
@@ -99,7 +103,6 @@ void login()
} }


try { try {
string usrnme, pswd;
cout << "Username:"; cout << "Username:";
cin >> username; cin >> username;


@@ -126,8 +129,6 @@ void login()


void registration() void registration()
{ {
string pswd = "2";
string pswd2 = "3";
bool available = true; bool available = true;


do do
@@ -157,16 +158,14 @@ void registration()
do do
{ {
cout << "Password : "; cout << "Password : ";
cin >> pswd;
cin >> password;


cout << "Confirm password :"; cout << "Confirm password :";
cin >> pswd2;
cin >> password2;


if (pswd != pswd2)
if (password != password2)
cout << "Password unmatched. Please try again."; cout << "Password unmatched. Please try again.";
} while (pswd != pswd2);

password = pswd;
} while (password != password2);


cout << "Email : "; cout << "Email : ";
cin >> email; cin >> email;
@@ -247,6 +246,7 @@ void update(Person newUser)
{ {
if (users.top().getName() == currentUser.getName()) if (users.top().getName() == currentUser.getName())
{ {
cout << "replaced" << endl;
newUsers.push(newUser); newUsers.push(newUser);
} }
else else
@@ -258,26 +258,29 @@ void update(Person newUser)
} }


users = newUsers; users = newUsers;
currentUser = newUser;
} }


void chgUsername() void chgUsername()
{ {
bool available = true;

bool available;
Person newUsers; Person newUsers;


do do
{ {
available = true;
cout << available << endl;
cout << "Username : "; cout << "Username : ";
cin >> username; cin >> username;


stack<Person> temp = users; stack<Person> temp = users;


for (int i = 0; i < x; i++)
while (!temp.empty())
{ {
if (temp.top().getName() == username) if (temp.top().getName() == username)
{ {
cout << "Username unavailable. Please try again." << endl; cout << "Username unavailable. Please try again." << endl;
cout << temp.top().getName() << " " << temp.top().getPhoneNo() << endl;
available = false; available = false;
break; break;
} }
@@ -300,15 +303,13 @@ void chgPassword()


while (!currentUser.checkPassword(password)) while (!currentUser.checkPassword(password))
{ {
cout << "Wrong password. Please try again.";
cout << "Wrong password. Please try again." << endl;
wrongPass++; wrongPass++;


cout << "Please input the current password : "; cout << "Please input the current password : ";
cin >> password; cin >> password;
} }


string password2;

do { do {
cout << "Please input the new password : "; cout << "Please input the new password : ";
cin >> password; cin >> password;
@@ -343,9 +344,10 @@ void quit()
{ {
ofstream fout("database.txt"); ofstream fout("database.txt");


for (int i = 0; i <= x; i++)
while (!users.empty())
{ {
fout << username[i] << " " << password[i] << " " << email[i] << " " << phoneNo[i] << " " << endl;
fout << users.top().getName() << " " << users.top().getPassword() << " " << users.top().getEmail() << " " << users.top().getPhoneNo() << " " << endl;
users.pop();
} }


exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);


+ 1
- 1
Person.cpp Näytä tiedosto

@@ -1,6 +1,6 @@
/* /*
* Written by : BinHong Lee * Written by : BinHong Lee
* Last edited : 4/22/2016
* Last edited : 5/11/2016
*/ */


#include <string> #include <string>


+ 2
- 1
database.txt Näytä tiedosto

@@ -1,3 +1,4 @@
binhonglee bhlee03655 binhonglee@hotmail.com +13479618886 binhonglee bhlee03655 binhonglee@hotmail.com +13479618886
binhong binhong binhong@binhong.me +14802527013 binhong binhong binhong@binhong.me +14802527013
who what why@binhong.me +where
who whut wtf_is_happening@binhong.me +999999999
testing password testing@binhong.me +601111111111

Ladataan…
Peruuta
Tallenna