random password generator in c
TRANSCRIPT
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 1/26
1
OBJECTIVE
The objective of this project is to generate the password randomly on providing the employee
details and store it in a separate text file. The password generated can be numeric, alphabetic andalphanumeric and all the passwords generated must be unique i.e. no two employees can have
the same password.
The Number of unique passwords generated through this project are quite large, so each
employee can be alloted a unique password. The password generated can be used by the
employee to have access to their account and to the company's information to which they are
authorized to.
Every effort has been made to generate a password that cannot be cracked easily but there is no
guarantee to protect passwords from brute-force cracking. However the password generated here
would take a considerable amount of time to crack.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 2/26
2
FEASIBILITY STUDY
A feasibility study is a preliminary study, which investigates the information needs of the user
and determines the proposed project.
In our study of the requirement, we found that the project is feasible and could be completed
within the time, cost and requirement (both software and hardware) constraints applied to it.
The main objective of the project is to apply a new method and new tools for maximum
efficiency which makes it feasible.
Problems are identified and reviewing related information solutions. Identifying measures or
indicators of system performance and the actions needed to improve or correct performance,
relative to the goal of the system.
Obtaining and seeing to the appropriate use of equipment, facilities, and materials needed to do
certain work.
Determining the kind of tools and equipment needed to make project work. Installing
equipments, machines, wiring or programs to meet specifications.
Performing routine maintenance on equipment and determining when and what kind of
maintenance is needed.
Observing, receiving and otherwise obtaining information from all relevant sources about their
all work activities. Communicating with people outside the organization, representing theorganizations to customers, public, government, and other external sources, to meet out their
expectations.
Developing specific goals and plans to prioritize, organise and accomplish your work.
The main objective of the project “Random Password Generator” is to reduce the time and
efforts on the part of the company to provide a unique password to each and every employee to
have access to only part of the information in the company that they are required to know. Thus
it helps in providing security in an organisation.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 3/26
3
SRS DOCUMENT
Random Password Generator
Input fields required by the user:
(i) Length of the password.
(ii) Type of password.
(iii) Employee name.
(iv) Employee id.
Operations:
(i) A random password is generated which is either a combination of numbers, lower and
uppercase letters, or of numbers and letters.
(ii) The random password generated is saved in a text file password.txt.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 4/26
4
SYSTEM DESIGN
The project “Random Password Generator” can be divided into five modules. They are as
follows:
• main module.
• Numeric random password generator module.
• Alphabetic random password generator module.
• Alphanumeric random password generator module.
• Compare module.
These modules are designed in C and the various features provided by it such as file handling,
standard library functions etc. The reason behind using C is because of its simplicity, easy to
implement approach and availability of a wide range of features. The various features of C used
in the development of current project are:-
• File handling.
• Standard C functions.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 5/26
5
DATABASE DESIGN
The DATABASE is designed using the FILES and is an essential part of the project. All the
random passwords generated are stored along with the employees information in the database
designed using FILES.
This file can be used by the company to provide access to the employees account by matching
the particulars entered by the employees.
The operations can be:
- Getting the input from the user.
- Matching it with the database.
- Providing access to the account only if the particulars are correct.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 6/26
6
MODULES
The various modules of the project “Random Password Generator” as classified and
implemented are:
main function
This module is used to take the input from the user such as employee name, employee id,
length of the password and type of the password. Based on the inputs provided by the user, this
module transfer the control to respective module.
Numeric_Password_Generator function.
This module generates a random numeric password of the length given by the user and then
compares it with the password database file. If the generated passsword is already present in the
database, then the code exits and needs to be called again for the same employee details.
Otherwise the generated password is stored along with employee details in the database file.
Alphabetic_Password_Generator function.
This module generates a random alphabetic password of the length given by the user whichis a combination of both lower and uppercase letters and then compares it with the password
database file. If the generated passsword is already present in the database, then the code exits
and needs to be called again for the same employee details. Otherwise the generated password is
stored along with employee details in the database file.
Alphanumeric_Password_Generator function.
This module generates a random alphanumeric password of the length given by the userwhich is a combination of both lower and uppercase letters and numbers and then compares it
with the password database file. If the generated passsword is already present in the database,
then the code exits and needs to be called again for the same employee details. Otherwise the
generated password is stored along with employee details in the database file.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 7/26
7
Compare function.
This module compares the password generated with the password field in the database file.
If the password is already present then this function returns false otherwise the control is
transferred to the respective module.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 8/26
8
FLOWCHARTS
MODULE 1 : main function
YES
NO
YES
NO
END
ENTER THE EMP NAME AND EMP ID
ENTER THE LENGTH
IF LENGTH >=8
AND
LENGTH <=12
ENTER THE TYPE OF PASSWORD
IF TYPE = NUMERIC
IF TYPE = ALPHABETIC
MODULE 1:NUMERIC_
PASSWORD_GENERATOR
MODULE 1:ALPHABETIC_
PASSWORD_GENERATOR
MODULE 1:ALPHANUMERIC
_PASSWORD_GENERATOR
STORE THE
PASSWORD IN
TEXT FILE.
PASSWORD.TXT
START
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 9/26
9
MODULE 2 : Numeric_Password_Generator function.
NO
YES
NO
YES
END
READ CHARACTER FROM FILE
IF CHARACTERIS EOF
IF COMPARE
(PASSWORD) IS 0
START
OPEN FILE STREAM
GENERATE NUMERIC PASSWORD
PUT EMPLOYEES NAME, ID AND
PASSWORD
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 10/26
10
MODULE 3 : Alphabetic_Password_Generator function.
NO
YES
NO
YES
END
READ CHARACTER FROM FILE
IF CHARACTERIS EOF
IF COMPARE
(PASSWORD) IS 0
START
OPEN FILE STREAM
GENERATE ALPHABETIC PASSWORD
PUT EMPLOYEES NAME, ID AND
PASSWORD
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 11/26
11
MODULE 4 : Alphanumeric_Password_Generator function.
NO
YES
NO
YES
END
READ CHARACTER FROM FILE
IF CHARACTERIS EOF
IF COMPARE
(PASSWORD) IS 0
START
OPEN FILE STREAM
GENERATE ALPHANUMERIC PASSWORD
PUT EMPLOYEES NAME, ID AND
PASSWORD
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 12/26
12
MODULE 5 : Compare function
NO
YES
YES
YES
NO
YES
NO
YES
END
READ CHARACTER FROM FILE
IF CHARACTER
IS EOF
START
SET FLAG=1
RETURN 1
READ THE PASSWORD FIELD
FROM FILE.
OPEN FILE STREAM
IF FLAG
IS 2
IF PASSWORD
PRESENT.SET
FLAG=2
RETURN 0
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 13/26
13
CODING
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<process.h>
#include<time.h>
#include<string.h>
void Numeric_Password_Generator(int x);
void Alphabetic_Password_Generator(int x);
void Alphanumeric_Password_Generator(int x);
int Compare(char *);
char empname[20],empid[10];
char password[15]={NULL};
void main()
{
int length,type;
clrscr();
printf("\nEnter the emp name:\n");
scanf("%s",empname);
printf("Enter the empid:\n");
scanf("%s",empid);
printf("Enter the length between 8 and 12:\n");
scanf("%d",&length);
printf("Type of password \n 1 : Numeric\n 2 : Alphabetic\n 3 : Alphanumeric \n");
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 14/26
14
scanf("%d",&type);
if(type==1)
Numeric_Password_Generator( (length);
if(type==2)
Alphabetic_Password_Generator( (length);
if(type==3)
Alphanumeric_Password_Generator( (length);
getch();
}
/* Numeric_Password_Generator Function.
This function generates the passwords of numeric types on providing the password length.
*/
void Numeric_Password_Generator (int l)
{
int i,pq;
time_t t;
FILE *fp;
char ch;
fp=fopen("Password.txt","a+");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 15/26
15
}
srand((unsigned)time(&t));
for(i=0;i<l;i++)
{
pq=rand()%10;
printf("%d",pq);
itoa(pq,(password+i),10);
}
if(Compare(password)==0)
{
fputs(empname,fp);
fputs("\t",fp);
fputs(empid,fp);
fputs("\t",fp);
fputs(password,fp);
fputs("\n",fp);
}
fclose(fp);
}
/*Alphabetic_Password_Generator Function.
The function generates the passwords consisting of random uppercase and lowercase letters on
providing the password length
*/
void Alphabetic_Password_Generator (int l)
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 16/26
16
{
int i,lp;
time_t t;
FILE *fp;
char ch;
fp=fopen("Password.txt","a+");
while(1)
{
ch=fgetc(fp);
if(ch==EOF)
break;
}
srand((unsigned)time(&t));
for(i=0;i<l;i++)
{
lp=random(58)+65;
if(lp>=91&&lp<=96)
{
i--;
continue;
}
printf("%c",lp);
password[i]=(char)lp;
}
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 17/26
17
if(Compare(password)==0)
{
fputs(empname,fp);
fputs("\t",fp);
fputs(empid,fp);
fputs("\t",fp);
fputs(password,fp);
fputs("\n",fp);
}
fclose(fp);
}
/* Alphanumeric_Password_Generator Function.
The function generates the passwords consisting of random numbers and letters on providing
the password length
*/
void Alphanumeric_Password_Generator (int l)
{
int i,lp;
time_t t;
FILE *fp;
char ch;
fp=fopen("Password.txt","a+");
while(1)
{
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 18/26
18
ch=fgetc(fp);
if(ch==EOF)
break;
}
srand((unsigned)time(&t));
for(i=0;i<l;i++)
{
lp=random(74)+48;
if(lp>=91&&lp<=96||lp>=58&&lp<=64)
{
i--;
continue;
}
printf("%c",lp);
password[i]=(char)lp;
}
if(Compare(password)==0)
{
fputs(empname,fp);
fputs("\t",fp);
fputs(empid,fp);
fputs("\t",fp);
fputs(password,fp);
fputs("\n",fp);
}
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 19/26
19
fclose(fp);
}
/*Compare Function
This function checks whether the randomly generated passwords exists in the password text file
or not.
If it does not exists, the generated password is copied to the text file otherwise not.
*/
int compare(char *pass)
{
char cm[25]={NULL},cha[13]={NULL},b;
int co,j=0,mp=1,i;
FILE *pt;
pt=fopen("Password.txt","r+");
b=fgetc(pt);
while(b!=EOF)
{
co=0;
j=0;
fgets(cm,26,pt);
for(i=0;i<strlen(cm)-1;i++)
{
if(co==2)
{
cha[j]=cm[i];
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 20/26
20
j++;
}
if(cm[i]=='\t')
co++;
}
//printf("\n %s %s",pass,cha);
if(strcmp(pass,cha)==0)
{
mp=2;
break;
}
for(i=0;i<13;i++)
{
cha[i]='\0';
}
b=fgetc(pt);
}
if(mp==1)
return 0;
else
return 1;
}
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 21/26
21
TEST CASES
TEST 1.
Enter the emp name: Shashank Gupta
Enter the empid: HCL214
Enter the length of the password between 8 and 12: 8
Type of password
1 : Numeric
2 : Alphabetic
3 : Alphanumeric
Enter the type: 1
43687008
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 22/26
22
TEST 2
Enter the emp name: Sourav Gautam
Enter the empid: HCL140
Enter the length of the password between 8 and 12: 10
Type of password
1 : Numeric
2 : Alphabetic
3 : Alphanumeric
Enter the type: 2
MGYjuVAGAJ
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 23/26
23
TEST 3.
Enter the emp name: Sunny Singh
Enter the empid: HCL234
Enter the length of the password between 8 and 12: 11
Type of password
1 : Numeric
2 : Alphabetic
3 : Alphanumeric
Enter the type: 3
qHylqRwLDbJ
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 24/26
24
FILE PASSWORD.TXT:-
Shashank Gupta HCL214 43687008
Sourav Gautam HCL140 MGYjuVAGAJ
Sunny Singh HCL234 qHylqRwLDbJ
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 25/26
25
CONCLUSION AND EXTENSION
I developed the following project named “Random Password Generator” to provide a tool to a
company for generating the passwords for its employees. The project is extremely easy tohandle. Project will eliminate all the tedious paper work involved in maintaining the employees
information. This project will provide a direct tool which will generate random passwords on
providing the employees information and will save it in a text file. The passwords generated are
quite secure and cannot be guessed easily. Also the numbers of passwords generated are quite
large(5*3*24*60*60 =12,96,000) so every employees can be alloted a unique passwords very
easily. Thus it will be beneficial for time management and for security purpose in a company.
The project can be further extended by making few maintainence such as
- By including the 32 special symbols, 34 control characters and 128 graphics character for
generating the password.
- By storing the personal details of an individual in a separate file along with the password
instead of storing all the details in a single file.
- The generated password can be used by the employee to log into their private accounts to
access company's information.
8/3/2019 Random Password Generator in c
http://slidepdf.com/reader/full/random-password-generator-in-c 26/26
REFERENCES
1. www.wikipedia.org
2. www.randpass.com
3. www.smartdraw.com
4. Wayne Stevens, Glen Myers, and Larry Constantine, “Structured Design.” IBM
Systems Journal, May 1974.
5. Tom DeMarco, Structured Analysis and Systems Specification. Englewood Cliffs,
Petrocelli/Charter, 1975.
6. Paul Ward, “The Transformation Schema: An Extension of the Dataflow Diagram to
represent Control and Timing.” IEEE Transaction on Software Engineering, February
1986, pp. 198-210.
7.
www.google.com8. www.cyberciti.biz/faq/generating-random-password.