Help me with this project?:

You will create a login system that allows a user to access his/her account. A successful login is defined when both the login and password match. Once a successful login occurs, the program should welcome the user by using their Employee ID.
Eg. Welcome Employee 6529
After 3 unsuccessful logins, the user will get an “Unauthorized Access Too Many Failed Login Attempts” message and will not be allowed to input any more login or password information. If a successful login occurs then the unsuccessful logins is reset back to zero.
Use the following id’s and passwords in your program.
Employee ID: 6529
Password: 6529
Employee ID: 2928
Password: 2928
Employee ID: 4646
Password: 4646
The program must be documented.
Eg.
/*
Programmer Name: Date: Assignment 1: Some information on what your program does.
*/
Please pick variable names that apply to that variable.

Dani AI

Generated

A concise plan that builds on the thread: asked for a login program, pointed out the storage-choice (hardcode vs file), and reminded posters that this forum helps with learning rather than doing the whole assignment. A simple, maintainable design is best: one small User record type, a function that verifies id/password pairs, a main loop that prompts for input, a configurable maxAttempts counter, and clear comments. Keep input handling and comparisons separate so swapping a hardcoded array for a file reader is trivial.

Minimal C skeleton showing the loop, safe input, comparison and attempt counting:

/* Author: Your Name
   Purpose: Simple login demo with attempt counting
*/

#include <stdio.h>
#include <string.h>

typedef struct { char id[16]; char pwd[16]; } User;

int find_user(const char *id, const char *pwd, const User users[], int n) {
    for (int i = 0; i < n; ++i)
        if (strcmp(users[i].id, id) == 0 && strcmp(users[i].pwd, pwd) == 0)
            return i;
    return -1;
}

int main(void) {
    User users[] = { {"EMP001","EMP001"}, {"EMP002","EMP002"}, {"EMP003","EMP003"} };
    const int nUsers = sizeof users / sizeof users[0];
    const int maxAttempts = 3;
    int failedAttempts = 0;
    char id[32], pwd[32];

    while (failedAttempts < maxAttempts) {
        printf("Enter ID: ");
        if (!fgets(id, sizeof id, stdin)) break;
        id[strcspn(id, "\n")] = '\0';

        printf("Enter password: ");
        if (!fgets(pwd, sizeof pwd, stdin)) break;
        pwd[strcspn(pwd, "\n")] = '\0';

        if (find_user(id, pwd, users, nUsers) >= 0) {
            printf("Login successful for employee %s\n", id);
            break;
        }
        failedAttempts++;
        printf("Incorrect credentials (%d/%d)\n", failedAttempts, maxAttempts);
    }

    if (failedAttempts >= maxAttempts)
        printf("Access denied: too many failed attempts\n");

    return 0;
}

Testing and pitfalls: use fgets and strip the newline (avoid scanf for strings), compare with strcmp (not ==), keep buffers sized to avoid overflow, and ensure the failed-attempt counter resets on successful login if that behavior is required. If you load accounts from a file, parse and trim each line, ignore blank lines, and validate the parsed fields.

Documentation and security: include a short file header and comments for each function. For homework, plaintext credentials are acceptable as a demo; for any real system use hashed, salted storage and secure APIs. The above skeleton is intentionally modular so it can be extended to file input, hashing, or a UI layer without rewriting the core logic.

Recommended Answers

All 7 Replies

Help you do what exactly? Write the program for you? No in this lifetime.

I assume you have a choice of whether you want to store those user names and passwords in a password text file or just hardcode them in your program. The instructions was ambiguous about that.

Create an infinite loop that prompts for user name and password, checks the list that you were given. If a match is found then exit the loop. Otherwise if no match was found let the program loop back to the beinning of the loop and ask again.

commented: no help +0

This is a project I have been working on, can anyone show me how to do it please?

If you have already been working on it, where is the pseudocode or c++ code that you have written?

If you have already been working on it, where is the pseudocode or c++ code that you have written?

HI AD, i think you again forgot that this is a c forum :)

>> think you again forgot that this is a c forum

I must be losing my mind in my old age :(

So can anyone do this for me? I really need it done and I do not understand it. I have been trying different exercises but I still do not get it, please help.

We're not a "do the program for you", forum. We help people with THEIR programs, if we can.

If you really have no code or pseudo code, at all, check out Google for homework sites, and see if you can find a "do it for you", forum.

Maybe hire a programmer? Won't help in a test, but it's something.

commented: not helpful +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.