Related questions
Concept explainers
Given following code and write comments for those code
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <ctype.h>
#define MAX_PASSWORD_LENGTH 128
#define MIN_PASSWORD_LENGTH 10
#define ALLOW_PASSPHRASE true
#define MIN_PHRASE_LENGTH 20
#define OPTIONAL_TESTS_REQUIRED true
#define MIN_OPTIONAL_TESTS_TO_PASS 4
bool isStrongPassword(char *password);
void printTestResults(char *password, bool isPassphrase, int optionalTestsPassed);
int main() {
char passwords[][128] = {
"password",
"mypassword",
"thisismypassword",
"passssword",
"This is my password phrase1",
"Tinypw1",
"Ireallydontlikehavingtomakeupnewpasswordsallthetime1",
"Iloveyouxxxooo1",
"Boom**********!",
"IHATEPWORDS1!",
"ihatepwords1!",
"IHatePwords!",
"IHatePwords",
"my pass phrase does not need to pass tests",
"short pass phrase",
"x",
"x1",
"Zxcvbnmnas7",
"Zxcvbnmnas~",
"Zxcvbnmnas7~"
};
for (int i = 0; i < sizeof(passwords) / sizeof(passwords[0]); ++i) {
bool isPassphrase = strchr(passwords[i], ' ') && strlen(passwords[i]) >= MIN_PHRASE_LENGTH;
int optionalTestsPassed = 0;
if (OPTIONAL_TESTS_REQUIRED) {
if (strpbrk(passwords[i], "abcdefghijklmnopqrstuvwxyz")) {
optionalTestsPassed++;
}
}
bool isPasswordStrong = isStrongPassword(passwords[i]) &&
(isPassphrase || optionalTestsPassed >= MIN_OPTIONAL_TESTS_TO_PASS);
printTestResults(passwords[i], isPassphrase, optionalTestsPassed);
printf("Strong? : %s\n", isPasswordStrong ? "true" : "false");
printf("Total optional tests passed: %d\n", optionalTestsPassed);
printf("\n");
}
return 0;
}
bool isStrongPassword(char *password) {
if (strlen(password) < MIN_PASSWORD_LENGTH) {
return false;
}
if (strlen(password) > MAX_PASSWORD_LENGTH) {
return false;
}
for (int i = 0; i < strlen(password) - 2; ++i) {
if (password[i] == password[i + 1] && password[i + 1] == password[i + 2]) {
return false;
}
}
return true;
}
void printTestResults(char *password, bool isPassphrase, int optionalTestsPassed) {
printf("Proposed password: %s\n", password);
printf("Failed Tests : ");
if (strlen(password) < MIN_PASSWORD_LENGTH) {
printf("[1] ");
}
if (strlen(password) > MAX_PASSWORD_LENGTH) {
printf("[2] ");
}
for (int i = 0; i < strlen(password) - 2; ++i) {
if (password[i] == password[i + 1] && password[i + 1] == password[i + 2]) {
printf("[3] ");
break;
}
}
printf("\n");
printf("Passed Tests : ");
if (strlen(password) >= MIN_PASSWORD_LENGTH && strlen(password) <= MAX_PASSWORD_LENGTH &&
!(strlen(password) > MIN_PHRASE_LENGTH && isPassphrase)) {
printf("[1-3] ");
}
if (optionalTestsPassed >= MIN_OPTIONAL_TESTS_TO_PASS || !OPTIONAL_TESTS_REQUIRED) {
printf("[4-7] ");
}
printf("\n");
printf("Required Test Errors : [\n");
if (strlen(password) < MIN_PASSWORD_LENGTH) {
printf("'The password must be at least %d characters long.'\n", MIN_PASSWORD_LENGTH);
}
if (strlen(password) > MAX_PASSWORD_LENGTH) {
printf("'The password must be fewer than %d characters.'\n", MAX_PASSWORD_LENGTH);
}
for (int i = 0; i < strlen(password) - 2; ++i) {
if (password[i] == password[i + 1] && password[i + 1] == password[i + 2]) {
printf("'The password may not contain a sequence of three or more repeated characters.'\n");
break;
}
}
printf("]\n");
printf("Optional Test Errors : [\n");
if (OPTIONAL_TESTS_REQUIRED) {
if (!(strpbrk(password, "abcdefghijklmnopqrstuvwxyz"))) {
printf("'The password must contain at least one lowercase letter.'\n");
}
}
printf("]\n");
printf("Is a Pass phrase : %s\n", isPassphrase ? "true" : "false");
}
Step by stepSolved in 4 steps with 5 images
- >> classicVinyls.cpp For the following program, you will use the text file called "vinyls.txt" attached to this assignment. The file stores information about a collection of classic vinyls. The records in the file are like the ones on the following sample: Led_Zeppelin Led_Zeppelin 1969 1000.00 The_Prettiest_Star David_Bowie 1973 2000.00 Speedway Elvis_Presley 1968 5000.00 Spirit_in_the_Night Bruce_Springsteen 1973 5000.00 ... Write a declaration for a structure named vinylRec that is to be used to store the records for the classic collection system. The fields in the record should include a title (string), an artist (string), the yearReleased (int), and an estimatedPrice(double). Create the following...arrow_forwardHome B Announcements - IT-140-J6182 zy Section 2.8 - IT 140: Introduction h Answered: Write a statement to 8 https://learn.zybooks.com/zybook/SNHUIT140V3/chapter/2/section/8 = zyBookS My library> IT 140: Introduction to Scripting v3 home> 2.8: Advanced string formatting E zyBooks catalog ? Help/FAQ 8 Jose Roque CHALLENGE 2.8.2: Format temperature output. АCTIVITY Print air_temperature with 1 decimal point followed by C. Sample output with input: 36.4158102 36.40 247772.2002516.qx3zqy7 1 air_temperature = float(input ()) 2 1 test 3 ' Your solution goes here ''' passed 4 All tests passed Activate Windows Go to Settings to activate Windows. 5:16 AM P Type here to search O 80°F Partly cloudy 7/10/2021 近arrow_forwardUsing Payton (write it as simple as possible)arrow_forward
- def read_flights(flights_source: TextIO, routes: RouteDict) -> FlightDir: """Return the flights from flights_source, including only the ones that have an entry in routes. >>> from io import StringIO >>> flight_src = StringIO(TEST_FLIGHTS_SRC) >>> actual = read_flights(flight_src, TEST_ROUTES_DICT_FOUR_CITIES) >>> actual == TEST_FLIGHTS_DIR_FOUR_CITIES True """ flights = [] src_index = FLIGHT_DATA_INDEXES["Source airport"] dst_index = FLIGHT_DATA_INDEXES["Destination airport"] # Complete this function. for line in routes_source:arrow_forwardThe code is below and use the code to answer the 3 questions that is attached as an image: #include <stdio.h>#include <stdlib.h>#include <unistd.h>#include <errno.h>#include <signal.h> void sigint_handler(int sig){ (void)sig; // remove unused variable warning write(0, "Ahhh! SIGINT!\n", 14);} int main(void){ void sigint_handler(int sig); /* prototype */ char s[200]; struct sigaction sa; sa.sa_handler = sigint_handler; sa.sa_flags = 0; // or SA_RESTART; sigemptyset(&sa.sa_mask); // if (sigaction(SIGINT, &sa, NULL) == -1) {// perror("sigaction");// exit(1);// } printf("Enter a string:\n"); if (fgets(s, sizeof s, stdin) == NULL) perror("fgets"); else printf("You entered: %s\n", s); return 0;}arrow_forwardSyntaxError: invalid syntax (<string>, line 56)arrow_forward
- Find a line with an error in the following code segment: 1: void displayFile(fstream file) {2: string line;3: while (file >> line) 4: cout << line << endl;5: } Group of answer choices 1 2 3 4arrow_forwardDO NOT COPY FROM OTHER WEBSITESarrow_forward#include <xc.h> void ____(void); void main (void) { TRISDbits.TRISD0 = ____;TRISDbits.TRISD1 = 0;TRISDbits.TRISD2 = ____;TRISDbits.TRISD3 = 0; ____ = 0; PORTDbits.RD0 = ____; PORTDbits.RD1 = 0; if(____ == 0)fail(); PORTDbits.RD0 = ____; PORTDbits.RD1 = 1; if(PORTDbits.RD2 == 0)fail(); ____ = 1; PORTDbits.RD1 = 0; if(____ == 0)____; PORTDbits.RD0 = ____; PORTDbits.RD1 = ____; if(PORTDbits.RD2 == ____)fail(); while(1) { PORTDbits.RD3 = 1; PORTDbits.RD4 = 0; } } void fail(void) { while(1) { PORTDbits.RD3 = ____; PORTDbits.RD4 = ____; } }arrow_forward
- Codearrow_forwardCreate a JavaFx application which calculate and add default gratitude (tips) to the a table bill and show the relevant information Business rules : • default 10% gratitude • table between 8 to 15: 15% gratitude • table more that 15: 20% gratitude The following information needed to be displayed on the designed application Table Total: $ 1000 Number of guesses: 20 Total Gratitude: 200ドル Sub Total: $ 1200 Tax (13%): $ 156 Payable: 1356ドル *** Make sure to apply any necessary validation you see fit for this application to avoid crashing your application *** validation messages may indicated on the window (stage) or pop out as an Alert() You may use any layout which you see fit.arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education