GoHacking.com: Ethical Hacking and Cyber Security
Home » C SOURCE CODES

C Program To Accept Password

Submitted by on Tuesday, 11 December 200712 Comments

This is a simple login program in C. While accepting password it masks each character using ‘*’ symbol and display the password in the next line after the user hits Enter key. It also accepts backspaces and acts accordingly.

 
#include<stdio.h>
#include<conio.h>

char pw[25],ch;
int i;
void main()
{
clrscr();
puts(“Enter password”);
while(1)
{
if(i<0)
i=0;
ch=getch();
if(ch==13)
break; /*13 is ASCII value of ENTER*/
if(ch==8) /*ASCII value of BACKSPACE*/
{
putch(‘\b’);
putch(NULL);
putch(‘\b’);
–i;
continue;
}
pw[i++]=ch;
ch=’*';
putch(ch);
}
pw[i]=’\0′;
printf(“\n\n%s”,pw);
getch();
}

Popularity: 2% [?]


Subscribe to GoHacking.Com


Enjoyed this article?
Subscribe to GoHacking.Com and get daily updates in your email for free


  By using/following this site you agree to our Legal Disclaimer

12 Comments »

  • Doodle77 said:

    Go home.

  • Anonymous said:

    Wats great in this?

  • Everyone said:

    Good

  • Virendra said:

    hi Shrikant,
    can you please tell me from where can i get c compiler

  • Srikanth (author) said:

    @ Virendra

    Goto Borland site. Or search on google for Turbo C/C++ compiler

  • crusader said:

    I was wondering if dev-c++ is a good compiler? and if it compiles in c also? Thanks

  • Akash said:

    Hi Srikanth Bro …
    I use Turbo c++ 3.1
    Which is the best for writing, Editing and compiling C Program ???

  • Anitha Jose Kurian said:

    Thankyou so much for the code for masking the password….I didn’t understand it fully but it helped a lot.

  • Arunim said:

    I Like But I Face An Error on it that 16 bit dos subsystem.What is this????????please help on this topic!!!!!!!!

  • Bibhuti said:

    great!!!!!!!!but it is not working on dev c++.what modification should be done??? plz reply….

  • munna prajapati said:

    Thanking you.

  • trong ky said:

    thank you very good article. but I’m running on turbo c saw many errors mean? would you help the address thank you very much taotau9x@gmail.com

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.