C++ Login Program: How to add Forget Password function
I recently created a simple C++ Login Program (check code below). However, I am not fully convinced unless I can solve the following issues I have in mind. I really need somebody's help with the following:
If I run the program for the first time, obviously I must not login successfully because there's no existing account, what can I do so that if I choose login and enter a username and password the program will output "Account does not Exist"
I also want the program to detect if I entered a wrong username or password to an existing account
How can I add forget password function?
Thank you so much.
#include<iostream>
#include<string>
#include<cstdlib>
#include<fstream>
using namespace std;
int choice;
bool cinfail;
int confirmation;
string username, password, password2;
void MainMenu();
void writetofile(string username){
ofstream writefile;
string file = username+".txt";
writefile.open(file.c_str());
writefile << password;
writefile.close();
MainMenu();
}
void login(){
system("cls");
cout<<"Username: "<<endl;
cin>>username;
cout<<"Password: "<<endl;
cin>>password;
if((username == username) && (password == password2)){
cout<<"SUCCESSFUL LOGIN!";
}
else{
cout<<"INVALID USERNAME OR PASSWORD!"<<endl;
}
}
void RegisterPassword(){
cout<<"Please enter the password: "<<endl;
cin>>password;
cout<<"Please reenter your password: "<<endl;
cin>>password2;
if(password == password2){
cin.clear();
cin.ignore(10000, 'n');
writetofile(username);
exit(1);
}
else{
cout<<"Sorry, invalid password. Try again."<<endl;
RegisterPassword();
}
system("cls");
}
void registerme(){
system("cls");
cout<<"REGISTER ACCOUNT"<<endl;
cout<<"Please enter your username: "<<endl;
getline(cin, username);
cout<<"nUsername - "" <<username<< ""nConfirm? nn[1] Yesn[2] No"<<endl;
cin>>confirmation;
if(confirmation == 1){
RegisterPassword();
}
else{
cout<<"Sorry, invalid input. Try again"<<endl;
cin.clear();
cin.ignore(10000, 'n');
registerme();
}
}
void exit(){
exit(0);
}
void MainMenu(){
cout<<"SIMPLE LOGIN PROGRAM by RZAMn[1] Loginn[2] Registern[3] Exit"<<endl;
cin>>choice;
do{
cinfail = cin.fail();
cin.clear();
cin.getline(10000,'n');
}while(cinfail == true);{
switch(choice){
case 1:
login();
break;
case 2:
registerme();
break;
case 3:
exit();
}
}
}
main(){
MainMenu();
}
c++
|
show 8 more comments
I recently created a simple C++ Login Program (check code below). However, I am not fully convinced unless I can solve the following issues I have in mind. I really need somebody's help with the following:
If I run the program for the first time, obviously I must not login successfully because there's no existing account, what can I do so that if I choose login and enter a username and password the program will output "Account does not Exist"
I also want the program to detect if I entered a wrong username or password to an existing account
How can I add forget password function?
Thank you so much.
#include<iostream>
#include<string>
#include<cstdlib>
#include<fstream>
using namespace std;
int choice;
bool cinfail;
int confirmation;
string username, password, password2;
void MainMenu();
void writetofile(string username){
ofstream writefile;
string file = username+".txt";
writefile.open(file.c_str());
writefile << password;
writefile.close();
MainMenu();
}
void login(){
system("cls");
cout<<"Username: "<<endl;
cin>>username;
cout<<"Password: "<<endl;
cin>>password;
if((username == username) && (password == password2)){
cout<<"SUCCESSFUL LOGIN!";
}
else{
cout<<"INVALID USERNAME OR PASSWORD!"<<endl;
}
}
void RegisterPassword(){
cout<<"Please enter the password: "<<endl;
cin>>password;
cout<<"Please reenter your password: "<<endl;
cin>>password2;
if(password == password2){
cin.clear();
cin.ignore(10000, 'n');
writetofile(username);
exit(1);
}
else{
cout<<"Sorry, invalid password. Try again."<<endl;
RegisterPassword();
}
system("cls");
}
void registerme(){
system("cls");
cout<<"REGISTER ACCOUNT"<<endl;
cout<<"Please enter your username: "<<endl;
getline(cin, username);
cout<<"nUsername - "" <<username<< ""nConfirm? nn[1] Yesn[2] No"<<endl;
cin>>confirmation;
if(confirmation == 1){
RegisterPassword();
}
else{
cout<<"Sorry, invalid input. Try again"<<endl;
cin.clear();
cin.ignore(10000, 'n');
registerme();
}
}
void exit(){
exit(0);
}
void MainMenu(){
cout<<"SIMPLE LOGIN PROGRAM by RZAMn[1] Loginn[2] Registern[3] Exit"<<endl;
cin>>choice;
do{
cinfail = cin.fail();
cin.clear();
cin.getline(10000,'n');
}while(cinfail == true);{
switch(choice){
case 1:
login();
break;
case 2:
registerme();
break;
case 3:
exit();
}
}
}
main(){
MainMenu();
}
c++
1. Is this a homework problem? I remember doing something like this is school 2. You would need to store username and passwords. Maybe in the text file. When registering user, add it 3. When logging in, you need to lookup the stored username, passwords from file
– user1451348
Nov 20 at 16:34
4
These aren't C++ questions. They are design questions. The answers are up to you. It is like asking, "How what do I paint a painting of?" Well, some people paint happy trees, others paint rectangles, some just get monkeys to throw paint at a canvas. They are all paintings, technically. The question is open ended and is really, "What are some common mechanisms for authentication?", and that warrants an entire book.
– Christopher Pisz
Nov 20 at 16:35
If the question is, "How do I parse key/value pairs from a file?", that is a different question. Another question might be "How do I add/remove an element from a key/value collection?" and you might have a third in there somewhere related to searching efficiently.
– Christopher Pisz
Nov 20 at 16:38
If you register enough users, you will encounter something this site is named after: stack overflow!MainMenucallingregistermecalling [two more] callingMainMenu.
– Aconcagua
Nov 20 at 16:47
Hi @user1451348 good day! actually this is not a homework, I am new to programming and I'm using C++ language. This is for my own programming collection :)
– Verax
Nov 20 at 16:50
|
show 8 more comments
I recently created a simple C++ Login Program (check code below). However, I am not fully convinced unless I can solve the following issues I have in mind. I really need somebody's help with the following:
If I run the program for the first time, obviously I must not login successfully because there's no existing account, what can I do so that if I choose login and enter a username and password the program will output "Account does not Exist"
I also want the program to detect if I entered a wrong username or password to an existing account
How can I add forget password function?
Thank you so much.
#include<iostream>
#include<string>
#include<cstdlib>
#include<fstream>
using namespace std;
int choice;
bool cinfail;
int confirmation;
string username, password, password2;
void MainMenu();
void writetofile(string username){
ofstream writefile;
string file = username+".txt";
writefile.open(file.c_str());
writefile << password;
writefile.close();
MainMenu();
}
void login(){
system("cls");
cout<<"Username: "<<endl;
cin>>username;
cout<<"Password: "<<endl;
cin>>password;
if((username == username) && (password == password2)){
cout<<"SUCCESSFUL LOGIN!";
}
else{
cout<<"INVALID USERNAME OR PASSWORD!"<<endl;
}
}
void RegisterPassword(){
cout<<"Please enter the password: "<<endl;
cin>>password;
cout<<"Please reenter your password: "<<endl;
cin>>password2;
if(password == password2){
cin.clear();
cin.ignore(10000, 'n');
writetofile(username);
exit(1);
}
else{
cout<<"Sorry, invalid password. Try again."<<endl;
RegisterPassword();
}
system("cls");
}
void registerme(){
system("cls");
cout<<"REGISTER ACCOUNT"<<endl;
cout<<"Please enter your username: "<<endl;
getline(cin, username);
cout<<"nUsername - "" <<username<< ""nConfirm? nn[1] Yesn[2] No"<<endl;
cin>>confirmation;
if(confirmation == 1){
RegisterPassword();
}
else{
cout<<"Sorry, invalid input. Try again"<<endl;
cin.clear();
cin.ignore(10000, 'n');
registerme();
}
}
void exit(){
exit(0);
}
void MainMenu(){
cout<<"SIMPLE LOGIN PROGRAM by RZAMn[1] Loginn[2] Registern[3] Exit"<<endl;
cin>>choice;
do{
cinfail = cin.fail();
cin.clear();
cin.getline(10000,'n');
}while(cinfail == true);{
switch(choice){
case 1:
login();
break;
case 2:
registerme();
break;
case 3:
exit();
}
}
}
main(){
MainMenu();
}
c++
I recently created a simple C++ Login Program (check code below). However, I am not fully convinced unless I can solve the following issues I have in mind. I really need somebody's help with the following:
If I run the program for the first time, obviously I must not login successfully because there's no existing account, what can I do so that if I choose login and enter a username and password the program will output "Account does not Exist"
I also want the program to detect if I entered a wrong username or password to an existing account
How can I add forget password function?
Thank you so much.
#include<iostream>
#include<string>
#include<cstdlib>
#include<fstream>
using namespace std;
int choice;
bool cinfail;
int confirmation;
string username, password, password2;
void MainMenu();
void writetofile(string username){
ofstream writefile;
string file = username+".txt";
writefile.open(file.c_str());
writefile << password;
writefile.close();
MainMenu();
}
void login(){
system("cls");
cout<<"Username: "<<endl;
cin>>username;
cout<<"Password: "<<endl;
cin>>password;
if((username == username) && (password == password2)){
cout<<"SUCCESSFUL LOGIN!";
}
else{
cout<<"INVALID USERNAME OR PASSWORD!"<<endl;
}
}
void RegisterPassword(){
cout<<"Please enter the password: "<<endl;
cin>>password;
cout<<"Please reenter your password: "<<endl;
cin>>password2;
if(password == password2){
cin.clear();
cin.ignore(10000, 'n');
writetofile(username);
exit(1);
}
else{
cout<<"Sorry, invalid password. Try again."<<endl;
RegisterPassword();
}
system("cls");
}
void registerme(){
system("cls");
cout<<"REGISTER ACCOUNT"<<endl;
cout<<"Please enter your username: "<<endl;
getline(cin, username);
cout<<"nUsername - "" <<username<< ""nConfirm? nn[1] Yesn[2] No"<<endl;
cin>>confirmation;
if(confirmation == 1){
RegisterPassword();
}
else{
cout<<"Sorry, invalid input. Try again"<<endl;
cin.clear();
cin.ignore(10000, 'n');
registerme();
}
}
void exit(){
exit(0);
}
void MainMenu(){
cout<<"SIMPLE LOGIN PROGRAM by RZAMn[1] Loginn[2] Registern[3] Exit"<<endl;
cin>>choice;
do{
cinfail = cin.fail();
cin.clear();
cin.getline(10000,'n');
}while(cinfail == true);{
switch(choice){
case 1:
login();
break;
case 2:
registerme();
break;
case 3:
exit();
}
}
}
main(){
MainMenu();
}
c++
c++
edited Nov 20 at 16:43
axalis
4,6751013
4,6751013
asked Nov 20 at 16:25
Verax
11
11
1. Is this a homework problem? I remember doing something like this is school 2. You would need to store username and passwords. Maybe in the text file. When registering user, add it 3. When logging in, you need to lookup the stored username, passwords from file
– user1451348
Nov 20 at 16:34
4
These aren't C++ questions. They are design questions. The answers are up to you. It is like asking, "How what do I paint a painting of?" Well, some people paint happy trees, others paint rectangles, some just get monkeys to throw paint at a canvas. They are all paintings, technically. The question is open ended and is really, "What are some common mechanisms for authentication?", and that warrants an entire book.
– Christopher Pisz
Nov 20 at 16:35
If the question is, "How do I parse key/value pairs from a file?", that is a different question. Another question might be "How do I add/remove an element from a key/value collection?" and you might have a third in there somewhere related to searching efficiently.
– Christopher Pisz
Nov 20 at 16:38
If you register enough users, you will encounter something this site is named after: stack overflow!MainMenucallingregistermecalling [two more] callingMainMenu.
– Aconcagua
Nov 20 at 16:47
Hi @user1451348 good day! actually this is not a homework, I am new to programming and I'm using C++ language. This is for my own programming collection :)
– Verax
Nov 20 at 16:50
|
show 8 more comments
1. Is this a homework problem? I remember doing something like this is school 2. You would need to store username and passwords. Maybe in the text file. When registering user, add it 3. When logging in, you need to lookup the stored username, passwords from file
– user1451348
Nov 20 at 16:34
4
These aren't C++ questions. They are design questions. The answers are up to you. It is like asking, "How what do I paint a painting of?" Well, some people paint happy trees, others paint rectangles, some just get monkeys to throw paint at a canvas. They are all paintings, technically. The question is open ended and is really, "What are some common mechanisms for authentication?", and that warrants an entire book.
– Christopher Pisz
Nov 20 at 16:35
If the question is, "How do I parse key/value pairs from a file?", that is a different question. Another question might be "How do I add/remove an element from a key/value collection?" and you might have a third in there somewhere related to searching efficiently.
– Christopher Pisz
Nov 20 at 16:38
If you register enough users, you will encounter something this site is named after: stack overflow!MainMenucallingregistermecalling [two more] callingMainMenu.
– Aconcagua
Nov 20 at 16:47
Hi @user1451348 good day! actually this is not a homework, I am new to programming and I'm using C++ language. This is for my own programming collection :)
– Verax
Nov 20 at 16:50
1. Is this a homework problem? I remember doing something like this is school 2. You would need to store username and passwords. Maybe in the text file. When registering user, add it 3. When logging in, you need to lookup the stored username, passwords from file
– user1451348
Nov 20 at 16:34
1. Is this a homework problem? I remember doing something like this is school 2. You would need to store username and passwords. Maybe in the text file. When registering user, add it 3. When logging in, you need to lookup the stored username, passwords from file
– user1451348
Nov 20 at 16:34
4
4
These aren't C++ questions. They are design questions. The answers are up to you. It is like asking, "How what do I paint a painting of?" Well, some people paint happy trees, others paint rectangles, some just get monkeys to throw paint at a canvas. They are all paintings, technically. The question is open ended and is really, "What are some common mechanisms for authentication?", and that warrants an entire book.
– Christopher Pisz
Nov 20 at 16:35
These aren't C++ questions. They are design questions. The answers are up to you. It is like asking, "How what do I paint a painting of?" Well, some people paint happy trees, others paint rectangles, some just get monkeys to throw paint at a canvas. They are all paintings, technically. The question is open ended and is really, "What are some common mechanisms for authentication?", and that warrants an entire book.
– Christopher Pisz
Nov 20 at 16:35
If the question is, "How do I parse key/value pairs from a file?", that is a different question. Another question might be "How do I add/remove an element from a key/value collection?" and you might have a third in there somewhere related to searching efficiently.
– Christopher Pisz
Nov 20 at 16:38
If the question is, "How do I parse key/value pairs from a file?", that is a different question. Another question might be "How do I add/remove an element from a key/value collection?" and you might have a third in there somewhere related to searching efficiently.
– Christopher Pisz
Nov 20 at 16:38
If you register enough users, you will encounter something this site is named after: stack overflow!
MainMenu calling registerme calling [two more] calling MainMenu.– Aconcagua
Nov 20 at 16:47
If you register enough users, you will encounter something this site is named after: stack overflow!
MainMenu calling registerme calling [two more] calling MainMenu.– Aconcagua
Nov 20 at 16:47
Hi @user1451348 good day! actually this is not a homework, I am new to programming and I'm using C++ language. This is for my own programming collection :)
– Verax
Nov 20 at 16:50
Hi @user1451348 good day! actually this is not a homework, I am new to programming and I'm using C++ language. This is for my own programming collection :)
– Verax
Nov 20 at 16:50
|
show 8 more comments
1 Answer
1
active
oldest
votes
For any forgotten passwords we would usually send an email asking if it's a legitimate request. You can't do that, maybe save the users date of birth when they login or a secret question. They can use this to enter a new password.
For detecting the wrong password to an existing account:
- Read all usernames into an array
- Check the entered username against all of them
- If the username exists, and the password is wrong you can alert the user.
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397334%2fc-login-program-how-to-add-forget-password-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
For any forgotten passwords we would usually send an email asking if it's a legitimate request. You can't do that, maybe save the users date of birth when they login or a secret question. They can use this to enter a new password.
For detecting the wrong password to an existing account:
- Read all usernames into an array
- Check the entered username against all of them
- If the username exists, and the password is wrong you can alert the user.
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
add a comment |
For any forgotten passwords we would usually send an email asking if it's a legitimate request. You can't do that, maybe save the users date of birth when they login or a secret question. They can use this to enter a new password.
For detecting the wrong password to an existing account:
- Read all usernames into an array
- Check the entered username against all of them
- If the username exists, and the password is wrong you can alert the user.
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
add a comment |
For any forgotten passwords we would usually send an email asking if it's a legitimate request. You can't do that, maybe save the users date of birth when they login or a secret question. They can use this to enter a new password.
For detecting the wrong password to an existing account:
- Read all usernames into an array
- Check the entered username against all of them
- If the username exists, and the password is wrong you can alert the user.
For any forgotten passwords we would usually send an email asking if it's a legitimate request. You can't do that, maybe save the users date of birth when they login or a secret question. They can use this to enter a new password.
For detecting the wrong password to an existing account:
- Read all usernames into an array
- Check the entered username against all of them
- If the username exists, and the password is wrong you can alert the user.
answered Nov 20 at 16:32
Reece Ward
256
256
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
add a comment |
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
Hello @Reece Ward thank you for the answer, however I don't quite understand your 2 and 3. Could you elaborate or provide snippets maybe? I would really appreciate it. Thanks!
– Verax
Nov 20 at 16:55
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53397334%2fc-login-program-how-to-add-forget-password-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1. Is this a homework problem? I remember doing something like this is school 2. You would need to store username and passwords. Maybe in the text file. When registering user, add it 3. When logging in, you need to lookup the stored username, passwords from file
– user1451348
Nov 20 at 16:34
4
These aren't C++ questions. They are design questions. The answers are up to you. It is like asking, "How what do I paint a painting of?" Well, some people paint happy trees, others paint rectangles, some just get monkeys to throw paint at a canvas. They are all paintings, technically. The question is open ended and is really, "What are some common mechanisms for authentication?", and that warrants an entire book.
– Christopher Pisz
Nov 20 at 16:35
If the question is, "How do I parse key/value pairs from a file?", that is a different question. Another question might be "How do I add/remove an element from a key/value collection?" and you might have a third in there somewhere related to searching efficiently.
– Christopher Pisz
Nov 20 at 16:38
If you register enough users, you will encounter something this site is named after: stack overflow!
MainMenucallingregistermecalling [two more] callingMainMenu.– Aconcagua
Nov 20 at 16:47
Hi @user1451348 good day! actually this is not a homework, I am new to programming and I'm using C++ language. This is for my own programming collection :)
– Verax
Nov 20 at 16:50