I need to make a C program that will take the password database from the file and check the password, and then it will display statistics. In the course of writing the program, I stopped at the moment when I needed to check the password according to certain criteria, and for 4 days I could not think of anything and fix it. Now I will attach a translation of my technical specification:
______________________________________________________________________________________
1. Startup parameters $ gcc -std = c99 -Wall -Wextra -Werror pwcheck.c -o pwchec
2. ./pwcheck LEVEL PARAMETERS [--stats]
--stats, if specified, controls whether summary statistics of parsed passwords should be displayed at the end of the program
LEVEL - an integer in the range [1, 4] indicating the required security level (see below)
PARAMETERS - is a positive integer indicating
additional rule parameter (see below)
3. Security levels (controlled rules)
List of rules:
lvl1 Password must contain at least 1 uppercase and 1 lowercase letter.
lvl2 The password contains characters from at least X groups (if the number X is greater than 4, this means all groups).
The following groups are considered:
1) lowercase letters (az)
2) uppercase letters (AZ)
3) numbers (0-9)
4) special characters (at least non-alphanumeric characters from the ASCII table in positions 33-126 32-126 should be supported, i.e. including space)
lvl3 Password does not contain the same sequence of characters at least X.
lvl4 Password does not contain two identical substrings at least X.
4. Statistics
If the specified program argument is --stats, the program should print general statistics at the end of the output in the format:
Statistics:
Various characters: NCHARS
Minimum length: MIN
Average length: AVG
NCHARS is the number of different characters found in all passwords
MIN is the length of the shortest password (or passwords)
AVG is the average password length (arithmetic mean), rounded to 1 decimal place
///// The statistics also include passwords that have been discarded.
5. Implementation details
1) Input data (list of passwords)
The list of passwords is passed to the program on standard input (stdin). Each password is entered on a separate line and contains only ASCII text data, excluding the newline character. The maximum password length is 100 characters, otherwise it is invalid data. The program must support an unlimited number of passwords at the entrance.
2) Program output
The standard output program (stdout) prints passwords from the input list, each on a separate line, that correspond to the required security level specified as an argument to the LEVEL program. Passwords should be listed unchanged and in the same order in which they were listed in the entry.
///// After displaying the list of passwords, the program additionally displays statistics (see Statistics).
6. Limitations in the project
The following functions are prohibited:
-calling functions from the string.h and ctype.h libraries - the goal of the project is to learn how to implement these functions manually,
-calls from the families malloc and free - working with dynamic memory is not needed in this project,
-calls from the fopen, fclose, fscanf, ... family - work with files is undesirable in this project (temporary),
-Calling the exit function - the goal of the project is to learn how to create program constructs that can handle an unexpected state of the program and, possibly, terminate the program correctly by returning from the main function.
____________________________________________________________________________________
I have been learning C for only a few weeks and I have already been asked to write this((((( I have attached my code, but it is still raw and not working, if you could correct at least this, I would be very grateful
What I have tried:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define CAPITAL (line[i]>='A' && line[i]<='Z')
#define SMALL (line[i]>='a' && line[i]<='z')
#define SPECIAL ((line[i]>=32&&line[i]<=47)||(line[i]>=58&&line[i]<=64)||(line[i]>=91&&line[i]<=96)||(line[i]>=123&&line[i]<=126))
int main(void) {
int i = 0, total = 0, capital=0 , small=0 , special=0;
char line[100][100];
FILE *plist = NULL;
plist = fopen("1te.txt", "r");
while(fgets(line[i], 80 , plist)) {
i++;}
total = i;
for(i = 0; i < total; ++i)
{
if((line[i]>='A' && line[i]<='Z'))
small=1;
if((line[i]>='a' && line[i]<='z'))
capital=1;
if(((line[i]>=32&&line[i]<=47)||(line[i]>=58&&line[i]<=64)||(line[i]>=91&&line[i]<=96)||(line[i]>=123&&line[i]<=126)))
special=1;
}
if(capital==0 || small==0 || special==0) printf("\n\tInvalid Password");
else
printf("\n\tValid Password");
getch();
return 0;
}