Showing posts with label password. Show all posts
Showing posts with label password. Show all posts

Tuesday, August 16, 2011

Saving Password in a file

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
char pw[100];
char *ptr;
int i=0;
FILE *fp;
clrscr();
printf("Enter the password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf("\b");
putch(NULL);
printf("\b");
pw[i]='\0';
--i;
}
else
{
printf("%c",ch);
putch('\b');
printf("*");
pw[i++]=ch;
}
ch=getch();
}
pw[i]='\0';
ptr=pw;
fp=fopen("c:\milan.txt","w");
while(*ptr!='\0')
{
fputc(*ptr,fp);
ptr++;
}
printf("\nPassword successfully saved in the file");
getch();
}

Comparing the password

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
char ch;
char pw[100];
char pswd[]="password";
int i=0;
clrscr();
printf("Enter the password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf("\b");
putch(NULL);
printf("\b");
pw[i]='\0';
--i;
}
else
{
printf("%c",ch);
putch('\b');
printf("*");
pw[i++]=ch;
}
ch=getch();
}
pw[i]='\0';
printf("\npassword is:%s",pw);
if(strcmp(pswd,pw)==0)
{
printf("\n password matched");
}
else
{
printf("\n password in wrong");
}
getch();
}

Saving the password in an array

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
char ch;
char pw[100];
int i=0;
clrscr();
printf("Enter the password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf("\b");
putch(NULL);
printf("\b");
pw[i]='\0';
--i;
}
else
{
printf("%c",ch);
putch('\b');
printf("*");
pw[i++]=ch;
}
ch=getch();
}
pw[i]='\0';
printf("\npassword is:%s",pw);
getch();
}

Delay in Password view

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
char ch;
clrscr();
printf("Enter the Password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
printf("\b");
putch(NULL);
printf("\b");
}
else
{
printf("%c",ch);
delay(500);
putch('\b');
printf("*");
}
ch=getch();
}
}

A program to implement the password view

This program will print the * whenever you press any digit and will also omit the last character after pressing the backspace..
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
ptintf("enter the password:\n");
ch=getch();
while(ch!=13)
{
if(ch==8)
{
putch('\b');
putch(NULL);
putch('\b');
}
else
{
printf("%c",ch);
putch('\b');
printf("*");
}
ch=getch();
}
}