Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- #include<string.h>
- #include<stdio.h>
- //#include "cipher.c"
- typedef struct node {
- char *username;
- char *password;
- char *usertype;
- struct node * next;
- } llnode;
- llnode* head;
- int menu(void);
- int addNode(char *username, char *password, char *usertype){
- llnode *addNode = (llnode *)malloc(sizeof(llnode));
- llnode *temp = (llnode *)malloc(sizeof(llnode));
- temp = head;
- while (temp != NULL){
- temp = temp -> next;
- }
- temp -> next = addNode;
- addNode -> username = username;
- addNode -> password = password;
- addNode -> usertype = usertype;
- addNode -> next = NULL;
- printf("%s , %s, %s", username, password, usertype);
- }
- int add(char *user, char* pass, char* usertype){
- printf("boooo2323");
- fflush(stdout);
- //FILE *file = fopen("password.csv", "at");
- //decrypt(file);
- printf("yoyoyo");
- //loadToLinkedList(file);
- llnode *temp = (llnode *)malloc(sizeof(llnode *));
- temp = head;
- temp = temp -> next;
- printf("boooo3");
- while(temp != NULL){
- if (strcmp(user, temp -> username)){
- temp = temp -> next;
- }
- else if (!strcmp(pass, temp -> password) && !strcmp(usertype, temp -> usertype)){
- printf("This record already exists!");
- }
- }
- addNode(user, pass, usertype);
- //backToTheFile(file);
- //encrypt(file);
- //fclose(file);
- return 0;
- }
- int delete(char * username){
- FILE *file = fopen("paswords.csv", "at");
- llnode *temp = (llnode *)malloc(sizeof(llnode *));
- llnode *cur = (llnode *)malloc(sizeof(llnode *));
- llnode *pcur = (llnode *)malloc(sizeof(llnode *)); //keeps track of previous node
- pcur = head;
- //decrypt(file);
- loadToLinkedList(file);
- cur = head -> next;
- while (cur != NULL){
- if (strcmp(username, cur -> username)){
- cur = cur -> next;
- pcur = pcur -> next;
- }
- else {
- pcur -> next = cur -> next;
- temp = cur;
- cur -> next = NULL;
- }
- if (strcmp(username, cur -> username) && cur -> next == NULL){
- printf("This record does not exist!");
- }
- }
- //addNode(username, pass, usertype);
- backToTheFile(file);
- //encrypt(file);
- fclose(file);
- return 0;
- }
- int edit(char *user1, char *user2, char *pass2, char* usertype2){
- delete(user1);
- add(user2, pass2, usertype2);
- }
- int verify(char *username, char* password){
- //FILE *file = fopen("passwords.csv", "wt");
- //decrypt(file);
- //loadToLinkedList(file);
- llnode *temp = (llnode *)malloc(sizeof(llnode *));
- temp = head;
- temp = temp -> next;
- int result;
- while(temp != NULL){
- if (strcmp(username, head -> username)){
- if (temp -> next == NULL){
- printf("INVALID\n");
- result = EXIT_FAILURE;
- break;
- }
- else
- temp = temp -> next;
- }
- else if (!strcmp(password, temp -> password)) {
- printf("VALID\n");
- result = EXIT_SUCCESS;
- break;
- }
- }
- //backToTheFile(file);
- //encrypt(file);
- //fclose(file);
- return result;
- }
- int menu(void){
- FILE *passwords = fopen("password.csv", "at");
- int choice;
- char *username = (char *)malloc(20*sizeof(char));
- char *password = (char *)malloc(20*sizeof(char));
- char *usertype = (char *)malloc(20*sizeof(char));
- char *user2 = (char *)malloc(20*sizeof(char));
- char *pass2 = (char *)malloc(20*sizeof(char));
- char *type2 = (char *)malloc(20*sizeof(char));
- while(1){
- printf(" Menu \n ---------- \n choose one of the following options:\n 1. add a record\n2. delete a record\n3. edit a record\n4. login verification\n5. quit\n");
- scanf("%d", &choice);
- switch(choice){
- case 1:
- printf("enter a username: \n");
- scanf("%s", username);
- printf("enter a password: \n");
- scanf("%s", password);
- printf("enter the user's type: \n");
- scanf("%s", usertype);
- add(username, password, usertype);
- break;
- case 2:
- printf("enter the username contained in the record you would like to delete: \n");
- scanf("%s", username);
- delete(username);
- break;
- case 3:
- printf("Enter the username contained in the record you would like to edit: \n");
- scanf("%s", username);
- printf("Enter the username of the new record: \n");
- scanf("%s", user2);
- printf("Enter the password of the new record: \n");
- scanf("%s", pass2);
- printf("Enter the type of the user: \n");
- scanf("%s", type2);
- edit(username, user2, pass2, type2);
- break;
- case 4:
- printf("Enter your username: \n");
- scanf("%s", username);
- printf("Enter your password: \n");
- scanf("%s", password);
- verify(username, password);
- break;
- case 5:
- backToTheFile(passwords);
- fclose(passwords);
- exit(0);
- break;
- default:
- break;
- }
- }
- //flose(password);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement