One of the things which attracted my attention was that there are often newbies asking how to create a password program in C/C++, often they don't succeed, well here's my response, you can use it for any purpose you want, one thing you'll have to keep in mind is that this code will only work on compilers which support conio.h, I know that it's actually a bad habit to make use of this "library", but most of the newbies which are searching for code like this are always using a compiler which supports it, so I guess that won't be a big problem.
As compiler to compile this code I used MinGW.
(The world's best open source compiler for Windows)
You can get the command line compiler from the site, however if you're new to
C/C++ then I would rather suggest you to go and get an IDE featuring the MinGW compiler: Code::Blocks is a very good one, also often used is the Dev-C++ IDE, but there's on major disadvantage of Dev-C++: The source code editor of the IDE isn't being updated anymore (however you can still use it with the newest MinGW compiler, that would be no problem)
C Password Program
#include <stdio.h>
#include <string.h>
#include <conio.h>
int main()
{
char buffer[256] = {0};
char password[] = "password";
char c;
int pos = 0;
printf("%s", "Enter password: ");
do {
c = getch();
if( isprint(c) )
{
buffer[ pos++ ] = c;
printf("%c", '*');
}
else if( c == 8 && pos )
{
buffer[ pos-- ] = '\0';
printf("%s", "\b \b");
}
} while( c != 13 );
if( !strcmp(buffer, password) )
printf("\n%s\n", "Logged on succesfully!");
else
printf("\n%s\n", "Incorrect login!");
return 0;
}
tux4life 2,072 Postaholic
tux4life 2,072 Postaholic
Asafe 0 Newbie Poster
tux4life 2,072 Postaholic
superdav42 0 Newbie Poster
tux4life 2,072 Postaholic
Kenclozand3 0 Newbie Poster
Noel Malle 0 Newbie Poster
aravindanne 0 Newbie Poster
Adytzu04 0 Newbie Poster
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Adytzu04 0 Newbie Poster
nilsonneto 0 Newbie Poster
np complete 8 Newbie Poster
deceptikon 1,790 Code Sniper Team Colleague Featured Poster
Ab000dy_85 -3 Junior Poster in Training
WaltP 2,905 Posting Sage w/ dash of thyme Team Colleague
Perla_1 0 Newbie Poster
Assembly Guy 72 Posting Whiz
BNF 0 Newbie Poster
usamaasghar.asghar 0 Newbie Poster
nonlinearly 0 Newbie Poster
Remy1990 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.