| | |
I'm lost..
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jan 2009
Posts: 151
Reputation:
Solved Threads: 3
Right, so I'm trying to create like a login system and my overall goal is to do it in classes but for the meantime, I won't. So this is my main file:
So, basically the checkDetails is going to check to see if the username and password match. But if they do, it runs another function "getUser" which displays all the users information but how do I do it because it's stored in a array? For example:
Wouldn't work, would it?
Thanks for any help and advice!
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iostream> #include "functions.h" using namespace std; void checkDetails(string user, string pass); string usernames[10]; string passwords[10]; int main(int argc, char *argv[]) { string user_username; string user_password; usernames[1] = 'Phillip'; usernames[2] = 'Phillip'; usernames[3] = 'Phillip'; passwords[1] = 'pass'; passwords[2] = 'pass2'; passwords[3] = 'pass3'; cout << "Please enter your username"; cin >> user_username; cout << "Please enter your password:"; cin >> user_password; checkDetails(user_username, user_password); system("PAUSE"); return 0; } void checkDetails(string user, string pass) { for(int i=0; (i < 10); i++) { if(user == usernames[i]) { if(pass == passwords[i]) { cout << "You're in the system"; }else{ cout << "You're not in the system"; }else { cout << "Your pass was not recognised"; } }
So, basically the checkDetails is going to check to see if the username and password match. But if they do, it runs another function "getUser" which displays all the users information but how do I do it because it's stored in a array? For example:
C++ Syntax (Toggle Plain Text)
getUsers(usernames[i]);
Wouldn't work, would it?
Thanks for any help and advice!
•
•
Join Date: Nov 2008
Posts: 397
Reputation:
Solved Threads: 72
0
#2 Oct 17th, 2009
What about adding a class. Starting with that is a great way to group data together.
But you may want to just use a token index e.g.
and then use the index number (e.g. your
This way you can either do something like this:
Note: You could sort your list of users and then when you have lots you don't need to loop through all of them.
Also: your current code prints a lot of "your pass was not regonised"
That needs to be after the loop if you don't find a user. So have another look at your if/else construction.
Think about using
Don't
c++ Syntax (Toggle Plain Text)
class UserInfo { private: std::string Name; std::string Pass; // THIS IS NOT SECURE int age; // etc... };
But you may want to just use a token index e.g.
c++ Syntax (Toggle Plain Text)
class UserDetails { std::string Name; int index; }
and then use the index number (e.g. your
i as a way of looking up a data-entry elsewhere. This way you can either do something like this:
c++ Syntax (Toggle Plain Text)
UserDetails* UPtr= findUser(Name); if (UPtr) UPtr->printUser(); // or: DataBaseObj DB; // stuff... if (UPtr) DB->printUser(UPtr->getIndex());
Also: your current code prints a lot of "your pass was not regonised"
That needs to be after the loop if you don't find a user. So have another look at your if/else construction.
Think about using
std::map<std::string,userClass> or std::vector<userClass> or something else other than a simple array. Since you will want to add new users later.Don't
use using namespace std; it simple defeats the objective of namespace std: to NOT pollute your global namespace. experience is the most expensive way to learn anything
0
#3 Oct 17th, 2009
You could pass the username and password arrays (or the single array of user objects when you make a class) to the checkDetails( ) function. That way you don't have the arrays in global space (something we want to avoid) and the function will not be tied to any specific array names.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
![]() |
Similar Threads
- recover lost file in windows XP (Windows NT / 2000 / XP)
- Body Text lost when sending hotmail (Web Browsers)
- Quick Launch toolbar lost (Windows 95 / 98 / Me)
- Lost browser links,internet options etc...toolbar (Web Browsers)
- Have I lost RAM? (Motherboards, CPUs and RAM)
- lost address book addresses (OS X)
- IDE devices lost during post W2K (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: Callback issues
- Next Thread: Can a function gives back function without pointers?
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy developer dll download dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph gui homeworkhelp iamthwee ifstream image input int java lib library linker list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






