Skip to content
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

Merged
merged 1 commit into from
Nov 1, 2024
Merged

Create Password.c #82

merged 1 commit into from
Nov 1, 2024

Conversation

o10a19
Copy link
Contributor

@o10a19 o10a19 commented Oct 31, 2024

Summary by Sourcery

New Features:

  • Implement a simple PIN verification program in C that allows up to three attempts to enter the correct PIN.

Copy link
Contributor

sourcery-ai bot commented Oct 31, 2024

Reviewer's Guide by Sourcery

This PR introduces a new C program that implements a simple PIN-based authentication system. The program allows users three attempts to enter the correct PIN (4008). It uses a do-while loop for PIN entry validation and includes proper error handling for failed attempts.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Implementation of a PIN verification system
  • Implements a PIN entry system with a hardcoded PIN (4008)
  • Provides three attempts for correct PIN entry
  • Includes error messages for incorrect PIN attempts
  • Terminates program with EXIT_FAILURE after three failed attempts
  • Displays welcome message upon successful authentication
C/Password.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @o10a19 - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Avoid hardcoding sensitive values like PINs in source code (link)
  • Use safer input methods instead of scanf to prevent buffer overflow vulnerabilities (link)

Overall Comments:

  • Storing the PIN directly in the source code is a serious security risk. Consider reading it from a secure configuration file or environment variable instead.
  • The program lacks input validation. scanf() could fail or overflow with invalid input. Consider adding proper error checking and using fgets() with sscanf() for safer input handling.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue found
  • 🔴 Security: 2 blocking issues
  • 🟢 Testing: all looks good
  • 🟡 Complexity: 1 issue found
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

scanf("%d", &pin);
attempt--;

if (pin != 4008) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.


do {
printf("Enter your pin: ");
scanf("%d", &pin);
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

printf("Incorrect PIN\n");
}

if (attempt == 0 && pin != 4008) {
Copy link
Contributor

Choose a reason for hiding this comment

The 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.

        if (attempt == 0) {
            printf("Incorrect PIN and no further attempts left\n");
            exit(EXIT_FAILURE);
        }

#include <stdio.h>

int main() {
int pin, attempt = 3;
Copy link
Contributor

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:

#include <stdlib.h>
#include <stdio.h>

#define CORRECT_PIN 4008
#define MAX_ATTEMPTS 3

int main() {
    int pin;
    int attempts_left = MAX_ATTEMPTS;

    while (attempts_left > 0) {
        printf("Enter your pin: ");
        scanf("%d", &pin);

        if (pin == CORRECT_PIN) {
            printf("Welcome User!\n");
            return 0;
        }

        attempts_left--;
        printf("Incorrect PIN\n");
        if (attempts_left == 0) {
            printf("No further attempts left\n");
            return EXIT_FAILURE;
        }
    }
}

@x0lg0n x0lg0n merged commit 0752474 into x0lg0n:main Nov 1, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants