-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path33th_program.c
More file actions
93 lines (88 loc) · 2.45 KB
/
33th_program.c
File metadata and controls
93 lines (88 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Write a program that shows the nesting of functions.
// This program is on salting and password checking .
#include<stdio.h>
#include<string.h>
#include <ctype.h>
void takepassword(); // This function take password
void takecpassword(); // This function take confirm password
void checkpassword( char password[]); // This function check length and strength of password
void salting(char password[]); // This function perform salting related tasks
char input_password[9],confirm_password[9];
int main()
{
takepassword();
return 0;
}
// Sub function section
void takepassword()
{
printf("Enter your password : ");
scanf("%s",input_password);
checkpassword(input_password);
}
void takecpassword()
{
printf("Reenter your password : ");
scanf("%s",confirm_password);
if(strcmp(input_password,confirm_password)==0)
{
salting(input_password);
}
else
{
printf("Confirm password must be same \n");
takecpassword();
}
}
void checkpassword(char password[])
{
if(strlen(password)==8)
{
int digit=0,smallcase=0,uppercase=0,specialchar=0;
for(int i=0;password[i]!='\0';i++)
{
if(isdigit(password[i]))
{
digit++;
}
else if (islower(password[i]))
{
smallcase++;
}
else if (isupper(password[i]))
{
uppercase++;
}
else if (ispunct(password[i]))
{
specialchar++;
}
else if (isspace(password[i]))
{
printf("Space is not allowed in password \n");
takepassword();
}
}
if(digit>=1 && smallcase>=1 && uppercase>=1 && specialchar>=1)
{
takecpassword();
}
else
{
printf("Password must have atleast one number,smallcase letters,uppercase letter and special characters(e.g., !, @, #, $, %, ^, &, *) \n\n");
takepassword();
}
}
else
{
printf("Password must be 8 characters long \n");
takepassword();
}
}
void salting(char password[])
{
char salt[]="123",salted_password[12];
strcpy(salted_password,password);
strcat(salted_password,salt);
printf("Salted password = %s \n",salted_password);
}