| | |
password function (c++)
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
hey guys, i'm using Borland 6 c++ in windows xp, now that we got that i have a problem with my program, i have recently created a password function in a programm that works so that when they try to type in their password it shows the * instead of the character for security measures (and just cus it is cool too lol) but the problem is that when someone makes a typo and wants to delete a character it still displays another *, is there a way that i can make the programm destroy one character when the backspace button is struck? here is my function so that you guys can look at it too.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio> #include <condefs.h> #pragma hdrstop #pragma argsused string EnterPassword(){ string numAsString = ""; char ch = getch(); while (ch != '\r') { cout << '*'; numAsString += ch; ch = getch(); } return numAsString; } void passfunction(); int main(int argc, char **argv) { passfunction(); return 0; } void passfunction() { cout << endl; cout << "password:"; string password = EnterPassword(); if( passowrd == "rbrown" ){ cout << "Hello Mr. Brown, Welcome back" << endl; system("PAUSE"); leave = true; return; } else if (password != "rbrown"){ cout << "incorrect password, please try again." << endl; system("PAUSE"); leave = false; passfunction (leave); } cout << password << endl; system("PAUSE"); return; }
Output a backspace ('\b') when on is input? And back up the string pointer and such?
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
•
•
Join Date: Mar 2007
Posts: 11
Reputation:
Solved Threads: 0
•
•
•
•
hey guys, i'm using Borland 6 c++ in windows xp, now that we got that i have a problem with my program, i have recently created a password function in a programm that works so that when they try to type in their password it shows the * instead of the character for security measures (and just cus it is cool too lol) but the problem is that when someone makes a typo and wants to delete a character it still displays another *, is there a way that i can make the programm destroy one character when the backspace button is struck? here is my function so that you guys can look at it too.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <conio> #include <condefs.h> #pragma hdrstop #pragma argsused string EnterPassword(){ string numAsString = ""; char ch = getch(); while (ch != '\r') { cout << '*'; numAsString += ch; ch = getch(); } return numAsString; } void passfunction(); int main(int argc, char **argv) { passfunction(); return 0; } void passfunction() { cout << endl; cout << "password:"; string password = EnterPassword(); if( passowrd == "rbrown" ){ cout << "Hello Mr. Brown, Welcome back" << endl; system("PAUSE"); leave = true; return; } else if (password != "rbrown"){ cout << "incorrect password, please try again." << endl; system("PAUSE"); leave = false; passfunction (leave); } cout << password << endl; system("PAUSE"); return; }
C++ Syntax (Toggle Plain Text)
#include <conio.h> #include <stdio.h> #include <string.h> #include <stdlib.h> #include <iostream.h> //***************************************************************************// //************Program for entering password of max 8 characters**************/ //************Press backspace if you make a mistake in the middle************// //************Press Enter once you are done**********************************// void main() { clrscr(); int i=0,j; char ch,temp[8],arr[8],*password; strcpy(arr,""); while(i<9) { ch=getch(); if(i==8&&(ch==13)) break; if(ch==8) { if(i!=0) i--; } else if(ch==13&&i<8) { temp[i]='\0'; break; } else if(i<8) { temp[i]=ch; arr[i]='*'; i++; } clrscr(); gotoxy(1,1); for(j=0;j<i;j++) cout<<arr[j]; } password=new char[i]; for(j=0;j<i;j++) password[j]=temp[j]; password[j]='\0'; cout<<"\nThe Password you typed is :";puts(password); getch(); }
I just wrote this small program.I know there may be 100 better ways to write it but this was the first program I wrote for handling passwords.You can always use the getpass() function but there is a catch with that.
•
•
Join Date: Mar 2007
Posts: 11
Reputation:
Solved Threads: 0
hmm..yes..That was before I joined this forum.Actually that was just my first post.I stumbled upon that by mistake and didnt see the date..And yeah I was really ignorant of the fact that you should never use void main().And the reason very obvious.."My teachers never told me it was wrong"..Anyways thats not an excuse..And about the outdated header..As I said that was written a long time ago on a now outdated Borland C++ 3.0..So its all my mistake..
Last edited by crazylunatic; Mar 31st, 2007 at 12:20 am.
![]() |
Similar Threads
- How to set up password to keep Windows from starting??? (Windows NT / 2000 / XP)
- Password protect code (JavaScript / DHTML / AJAX)
- php drop down menu to search multiple sql tables (PHP)
- Insert Encrypted Password (ASP)
- Not able to change/update password (PHP)
- Password - Adobe Acrobat (Visual Basic 4 / 5 / 6)
- Input a "password" string (C++)
- My PC won't remember or ask for password recall (Windows NT / 2000 / XP)
Other Threads in the C++ Forum
- Previous Thread: File Handling using C++
- Next Thread: Help me understand the syntax, Urgent
| 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 data 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 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






