I'm currently working on a ATM program wherein a 3.5 floopy diskette would serves as the card of the user. this diskette has a program wherein it has a account number and a password.

And when the user inserted a diskette, he will be instructed to input his password and when the password is the same,a menu will appear and choose what kind of transaction he would like to do.
my problem in my program is this::

I don't know how to compare the password inputted by the user whether it tallies with the password of inserted diskette. I think that i need to use a file pointer but i don't know how! i just know how to read and write using the file pointer. can anyone help me?!!!

Dani AI

Generated

A compact, practical pattern for (and as and noted, showing code helps) — open the "card" file, read the stored password safely, read the typed password safely, strip trailing CR/LF, then compare with strcmp. Key points: always check fopen/fgets return values, never use gets, limit buffer sizes to avoid overflow, and strip newlines before comparing.

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

#define MAX_PASS 128

/* returns 1 = match, 0 = no match, -1 = error */
int verify_password(const char *card_path) {
    char stored[MAX_PASS];
    char entered[MAX_PASS];

    FILE *f = fopen(card_path, "r");
    if (!f) { perror("fopen"); return -1; }

    if (!fgets(stored, sizeof stored, f)) { fclose(f); return -1; }
    fclose(f);
    stored[strcspn(stored, "\r\n")] = '\0'; /* remove CR/LF */

    printf("Password: ");
    if (!fgets(entered, sizeof entered, stdin)) return -1;
    entered[strcspn(entered, "\r\n")] = '\0';

    return strcmp(stored, entered) == 0;
}

Notes and troubleshooting:

  • If the card file has multiple fields, read the correct line or parse fields with fgets + sscanf or strtok.
  • For fixed-length records (binary card image) use fread and compare fixed buffers.
  • Handle file paths carefully for removable drives (platform differences: "A:\file" on Windows vs "/media/..." on Unix).
  • Add file locking if concurrent access is possible.

Security caution:

  • Storing plaintext passwords on removable media is insecure. For anything beyond a class exercise, store a salted hash (bcrypt/Argon2) instead and compare hashes. On C, use a vetted crypto library (libsodium/OpenSSL) rather than home-rolled hashing.
  • Treat floppy-based authentication as insecure for real ATMs; this pattern is only for learning/debugging.

Recommended Answers

All 3 Replies

Post the code you've begun to develop, and please use code tags.

By posting your starting attempt, at least we can know whether you are using C or C++ since you didn't mention it.

well i'm using C in this program.

well i'm using C in this program.

Saying that won't help unless you show what you have tried till now.

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.