-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create Password.c #82
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
int main() { | ||
int pin, attempt = 3; | ||
|
||
do { | ||
printf("Enter your pin: "); | ||
scanf("%d", &pin); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Use safer input methods instead of scanf to prevent buffer overflow vulnerabilities Consider using fgets() with sscanf() or similar safer alternatives that provide better input validation and buffer overflow protection. |
||
attempt--; | ||
|
||
if (pin != 4008) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Avoid hardcoding sensitive values like PINs in source code Consider storing the PIN in a secure configuration file or environment variable, or using a proper password hashing mechanism. |
||
printf("Incorrect PIN\n"); | ||
} | ||
|
||
if (attempt == 0 && pin != 4008) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Restructure the attempt checking logic to avoid duplicate messaging Consider checking remaining attempts first, then validate the PIN to make the flow more logical and eliminate redundant messages.
|
||
printf("Incorrect PIN and no further attempts left\n"); | ||
exit(EXIT_FAILURE); | ||
} | ||
} while (pin != 4008); | ||
|
||
printf("Welcome User!\n"); | ||
return 0; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider using symbolic constants and a single return path to improve code clarity.
The control flow can be simplified while maintaining all functionality. Here's a cleaner approach: