Important alert: (current site time 11/26/2014 2:10:20 AM EDT)
 

VB icon

simplest password program

Email
Submitted on: 11/28/2004 6:25:21 AM
By: Jebin Abraham Pullukalayil 
Level: Beginner
User Rating: By 5 Users
Compatibility: C++ (general), Microsoft Visual C++, Borland C++
Views: 29231
 
     simplest password program... displays "*" as each letter is typed... enable backspace... good efficient
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
//**************************************
// Name: simplest password program
// Description:simplest password program... displays "*" as each letter is typed... enable backspace... good efficient
// By: Jebin Abraham Pullukalayil
//
// Assumes:you just need to know what pointers are that's all for this program...
//
//This code is copyrighted and has// limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=8637&lngWId=3//for details.//**************************************

/* the most simplest logic and most simplest password program that enables
backspace character ... just need to know what pointer and basics of
pointer arithematic
that's all just that much...*/
#include <stdio.h> //for puts()
#include <conio.h> //for getch(), getche()..etc...
#include <iostream.h>//for (cout,cin)
#include <string.h>//for strcmp()
void p1()
{
 clrscr();//display screen... of course...
 cout<<"\n ENter the password ";
}
/* Basic pecularity for good basic and simple password program is that the password
that one is typing, should not come on the screen... and that's there in this program*/
char* pass()
{
 char* password, *sub;//the password string and sub -> well i'll tell u later
 char ch;//the character that yer gonna enter
 int n=0,m;
/*
 n->keeps track of stars that are displayed
 m->well... i'll tell u later...
*/
 sub=password;
/*now in this statement we store the password's 0th location in sub
 you will understand why i am doing this later...*/
 p1();
 int i=0; // i-> keep track of password
 ch=getch();
 /*
well i used getch() becoz it gets character
from the keyboard, does not echo to screen.
for example if the input is 'j' if you enter
'j' still the screen would appear blank...
 */
 do
 {
 if (ch!='\b')
 {
 cout<<"*";
 /*as soon as you enter a character you want a
star to be displayed. so thats the command...*/
 n++; //no of stars is incremented
 *password=ch;//ch stored in password
 i++; //i increments
 password++; //now password will point to next location
 }
 /*now all this will only take place if
ch is not backspace '\b'*/
 /* now the question comes "WHAT SHOULD BE DONE IF THE CHARACTER ENTERRED IS BACKSPACE???"
 now for example your original password is "INDIA" and now you have accidently entered
 "INDD".
 so you have to delete the D there from the password and also you have to delete one star
 from the output..
 just follow the following simple steps
 (1) display the display screen once more.
 (2) decrement the password pointer... right now it will pointing to the next location after
 the second D. you want to overwrite the D. so you'll have to decrement password so
 that it points now to second D;
 (3) decrement n because you don't want the 4the star that has appeared.
 (4) now display n stars that is the computer will display 3 stars now...
 */
 else if (ch=='\b')
 {
 p1();
 if (password!=sub)
 {
 password--;
 i--;
 m=n; //m is simple variable that's used. i dont want to touch my n...
 n--;
 for (; m>1; m--)
cout<<"*"; // displays the new no. of stars
 }
 /* this condition above is just a small correction factor required in the program...
 well for example if the if statement was not there, just imagine that the password
 was "INDIA" and you by mistake typed "PAKISTAN" now you use the backspace and delete...
 like that you delete pakistan after you delete pakistan you by miskatedly pressed backspace
 2 more times and then you enterred india...
 Now the password that is stored will be dia instead of india because location of password
 will get substracted to a position lower that it's intial position or 0th position so when we
 enter i and n it's will be stored some addreess that come before password and dia will be stored
 in the password... so we need to stop accepting the backspaces when we reach the intial position.
 Well the correct this factor this if statement is used...
 sub has already password's intial address so the condition will check whether password has
 reached the initial address(i.e. all letters deleted). If the position of password is not the
 intial positon(ie. no equal to sub's position) the only it will decrement and i will be substracted.
 other wise it'll proceed forward that's it...*/
 }
 ch=getch();//same proceedure follows unless enter is encountered.
 }while(ch!='\r');
 *password='\0'; //last part of password is entered as null
 for (; i>0; i--)
 password--;//BRINGING THE POINTER TO FIRST LOCATION
 return password;//RETURN POINTER
}
void main()
{
 char* pa;
 pa=pass();//RECIEVING THE PASSWORD
 int m, n,i;
 m=n=0;
 i=strlen(pa);
 cout<<"\n The password that you enterred just now is ";
 puts(pa);
 cout<<"\n It's of length "<<i;
 getche();
}
/* well u can use this program anywhere you want cause i agree with just one thing
**"A CANDLE DOES NOT LOSE ANYTHING WHILE LIGHTING ANOTHER CANDLE"**/


Other 4 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

11/28/2004 6:34:06 AMSanchit Karve

Well...nice code but unnecessary. The C++ library already a better alternative. The getpass() function is used to accept passwords, is more secure that even the asteriks aren't shown. getpass() is even used in UNIX.
(If this comment was disrespectful, please report it.)

 
12/4/2004 4:19:19 PMJebin Abraham Pullukalayil

the real problem with getpass() function is that it does not show the number of characters the user has typed on the screen. this can create a confusion...

just for example the password is INDIA and your "I" key is not working properly on the keyboard.

so if getpass() is used the person can't know whether the I that he typed has been accepted by the problem..

so i guess to counter these thing well i think we got to turn towards the "*" stuff rather that use getpass()
(If this comment was disrespectful, please report it.)

 
12/13/2004 8:39:44 AM

where can i direct download a c++ program to write this code but the program must have less than 5 MB because i'm with dial-up connection
(If this comment was disrespectful, please report it.)

 
12/16/2004 4:26:48 PMJosh Olivier

2 mb http://community.borland.com/museum
7.5 mb http://www.bloodshed.net/devcpp.html
kahuna149@yahoo.com
peace out
(If this comment was disrespectful, please report it.)

 
2/24/2005 3:21:06 AM

char* password, *sub;
.
.
*password = ch;

Well you have used the pointer which is not initialized (thus, has a random place in the memory) and this can lead to any kind of corruption in memory if the password points to a used memory block. I would rather add a line of code like malloc and warn the user or do not allow adding more than x characters.
(If this comment was disrespectful, please report it.)

 
3/4/2005 5:48:54 AMJebin Abraham Pullukalayil

i hope you are correct. well.... i'll try to correct it later....
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.