Question

A CERTAIN program to user's password containing rules such as least n length, one uppercase, lowercase, one digit and white space is given as the code down below. So, simiiar to those rules, I need the code for the following questions post in pictures such as no more three consecutive letters of English alphabets, password should not contain User name and so on.

//GOAL: To learn how to create that make strong passwords

//Purpose: 1)To learn some rules that makes strong passwords

// 2)To understand basic character function such as:

// 1)isalpha(), 2)isdigit(), 3)isalnum(), 4)islower()

// 5)isupper(), 6)ispunct(), 7)isprint(), 8)isspace(), 9)toupper(), 10)tolower()

// 3) To understand how to use basic string function such as:

// i)strlen(s1), ii)strcpy(s1,s2) like s1 = s2

// iii)strcat(s1,s2) concatenates s2 to the end of s1

// iv)strcmp(s1,s2) which returns the difference of the ASCII value of the first

// two non-matching characters in string s1 and s2.

#include<stdio.h>

#include<ctype.h>

#include<string.h>

#define MAX_STRING_LENGTH 20

int main()

{

char s1[ MAX_STRING_LENGTH];

int n;

printf("\n Please enter the string that you would like as your passwor:");

//scanf("%s",s1);

gets(s1);

printf("\n The password you have chosen is: %s", s1);

printf("\n What is the minimun length of a good/strong passwor:");

scanf("%d",&n);

if (strlen(s1)< n)

{

printf("\n Your password does not qualify, since it is not long enough!!");

printf("\ Your password if of length %d. Minimum password length is %d", strlen(s1),n);

}

else

{

printf("\n You have chosen a good password. It meet the minimun length criterion.");

}

// Rule 2.

//..............................................................................................

int i;

int num_lower = 0;

int num_upper = 0;

int num_digit = 0;

for( i =0; i<=strlen(s1) -1; i++)

{

if(isupper(s1[i]))

{

num_upper ++;

}

if (islower(s1[i]))

{

num_lower ++;

}

if (isdigit(s1[i]))

{

num_digit ++;

}

}

if (num_upper >0 && num_lower >0 && num_digit >0)

{

printf("\n The password is Stong , because it has lowercase character,\n");

printf("\n Uppercase characters, and digit in the password.");

printf("\n Your password is strong, since it meets the Rule 2:");

}

// Rule 3: Add a non-alphabetic character that is not a digit

//..........................................................

int num_special_character = 0;

for(i=0; i<=strlen(s1)-1; i++)

{

if(! isalnum(s1[i]))

{

num_special_character ++;

}

}

if (num_special_character == 0)

{

printf("\ Your password is not good....");

printf("\ It is missing a special character, such as +-*/<>...etc.");

}

else

{

printf("\n Your password is strong, since it meets the Rule 3:");

}

//Rule:4

//..................................

int num_whitespaces_total =0;

for( i=0; i<=255; i++)

{

if(isspace(i))

{

printf("\n %d %c is a white space", i,i);

num_whitespaces_total ++;

}

}

printf("\n The 8-bit Extended ASCII code.... has %d WHITE SPACE CHARACTER", num_whitespaces_total);

int num_white_spaces =0;

for( i=0; i<=strlen(s1)-1; i++)

{

if(isspace(s1(i)))

{

printf("\n %d %c is a white space", i,i);

num_white_spaces ++;

}

}

if (num_white_spaces == 0)

{

printf("\n Your password is bad:");

}

else

{

printf("It good password:");

}

getchar();

return 0;

}

Develop a code for C program to make sure that your program has the following rules. Add the following rule: The password should not contain any word from the dictionary You may use your dictionary from Assignment Add the following rule: Your password should not contain three or more consecutive letters of the English al also disallow 3 consecutive digits. e.g. abcd1234temp would be considered a bad password. phabet. You should Add the following rule: Your password should not contain three or more consecutive letters of the English alphabet that are adjacent keys on the keyboard. You should also disallow 3 consecutive digits. e.g.. qwerty 123asdfg would be considered a bad password. Your password should not contain the User name. No three consecutive letters of the User name should be allowed in the password. e.g.. Username: Mike Password: Mike23vnkdtrp8 should not be allowed. Write a short note on the difficulties you encountered in implementing your password checker program above. Explain how you overcame those difficulties. How strong is your password? Explain briefly. State (but not implement) any 2 additional criteria for an even stronger password. How hard would they be to implement? Explain.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<stdio.h>

#include<ctype.h>

#include<stdlib.h>

#include<string.h>

#define MAX_STRING_LENGTH 20

int main(int argc, char const *argv[])

{

char s1[ MAX_STRING_LENGTH];

printf("\n Please enter the string that you would like as your passwor:");

gets(s1);

printf("\n The password you have chosen is: %s\n", s1);

// Rule 1 - The password should not contain any word from dictionary

/*

Since, I don't have access to dictionary. I will skip it here

*/

// Rule 2 - The password should not contain 3 or more consecutive english alphabets

int consecutive_english_alpha_count = 0, i=0;

int good_password = 1;

for(i=0; i< strlen(s1); i++)

{

if(isalpha(s1[i])) {

consecutive_english_alpha_count++;

}

else {

consecutive_english_alpha_count = 0;

}

if(consecutive_english_alpha_count == 3) {

good_password = 0;

break;

}

}

if(good_password == 1)

{

printf("Great Password as it didn't have 3 consecutive english alphabets\n");

}

else

{

printf("OOPs! Your password have 3 consecutive english characters\n");

}

// Rule 3 - Password having 3 or more consecutive english characters from keyboard

// keyboard below containes all adjacent charaters on keyboard

char *keyboard = "qwertyuiopasdfghjklzxcvbnm";

// now we will generate all substring of length 3 from password and search that substring in

// the keyboard string. If we found the match, then password is bad else good

int k = 3;

good_password = 1;

for(i=0; i+k-1<strlen(s1); i++)

{

char *temp = (char*) malloc(k);

strncpy(temp, s1+i, k);

// printf("substring from %d is %s\n", i, temp );

if(strstr(keyboard, temp) != NULL) {

good_password = 0;

break;

}

}

if(good_password == 1)

printf("Good Password! No 3 adjacent characters found in password which are present in keyboard\n");

else

printf("Bad Password! 3 adjacent characters found in password which are also present in keyboard\n");

// Rule 4 - No 3 consecutive letters of username present in password

// First we will take the user input

char user[MAX_STRING_LENGTH];

printf("\n Please enter the username: ");

gets(user);

printf("\n The username you have entered is: %s\n", user);

// We will follow the same approach as Rule 3. The only change is keyboard pointer is replaced with username

// now we will generate all substring of length 3 from password and search that substring in

// the username string. If we found the match, then password is bad else good

good_password = 1;

for(i=0; i+k-1<strlen(s1); i++)

{

char *temp = (char*) malloc(k);

strncpy(temp, s1+i, k);

// printf("substring from %d is %s\n", i, temp );

if(strstr(user, temp) != NULL) {

good_password = 0;

break;

}

}

if(good_password == 1)

printf("Good Password! No 3 adjacent characters found in password which are present in username\n");

else

printf("Bad Password! 3 adjacent characters found in password which are also present in username\n");

return 0;

}

Add a comment
Know the answer?
Add Answer to:
A CERTAIN program to user's password containing rules such as least n length, one uppercase, lowercase,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. You are given a C file which contains a partially completed program. Follow the instructions...

    1. You are given a C file which contains a partially completed program. Follow the instructions contained in comments and complete the required functions. You will be rewriting four functions from HW03 (initializeStrings, printStrings, encryptStrings, decryptStrings) using only pointer operations instead of using array operations. In addition to this, you will be writing two new functions (printReversedString, isValidPassword). You should not be using any array operations in any of functions for this assignment. You may use only the strlen() function...

  • Note that the main function that I have provided does use <string.h> as it constructs test...

    Note that the main function that I have provided does use <string.h> as it constructs test strings to pass to your functions. However, your solutions for the 5 functions below may not use any of the built-in C string functions from the <string.h> library. Write a function called strcmp373. This function is passed two parameters, both of which are C strings. You should use array syntax when writing this function; that is, you may use [ ], but not *...

  • CSC Hw Problems. Any help is appreciated I dont know where to start let alone what...

    CSC Hw Problems. Any help is appreciated I dont know where to start let alone what the answers are. Your assignment is to write your own version of some of the functions in the built-in <string.h> C library. As you write these functions, keep in mind that a string in C is represented as a char array, with the '\0' character at the end of the string. Therefore, when a string is passed as a parameter, the length of the...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names,...

    Lab 2: (one task for Program 5): Declare an array of C-strings to hold course names, and read in course names from an input file. Then do the output to show each course name that was read in. See Chapter 8 section on "C-Strings", and the section "Arrays of Strings and C-strings", which gives an example related to this lab. Declare the array for course names as a 2-D char array: char courseNames[10] [ 50]; -each row will be a...

  • For a C program hangman game: Create the function int play_game [play_game ( Game *g )]...

    For a C program hangman game: Create the function int play_game [play_game ( Game *g )] for a C program hangman game. (The existing code for other functions and the program is below, along with what the function needs to do) (Also the link to program files (hangman.h and library file) is below the existing code section. You can use that to check if the code works) What int play_game needs to do mostly involves calling other functions you've already...

  • In python, write the following program, high school question, please keep simple. When I submitted the...

    In python, write the following program, high school question, please keep simple. When I submitted the solution, I get an error as 'wrong answer'. Please note below the question and then the solution with compiler errors. 7.2 Code Practice: Question 2 Instructions Write a program to generate passwords. The program should ask the user for a phrase and number, and then create the password based on our special algorithm. The algorithm to create the password is as follows: If the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT