Click here to Skip to main content
15,889,335 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
#include <stdio.h>
#include <string.h>
#include <windows.h>

void checkGuest();
int calculateDate(int m1, int d1,int y1,int m2,int d2,int y2);

int main()
{
    const char  ADMINUSER[20]="admin",
                ADMINPASS[20]="admin246";

    char user[10],pass[10];
    int access=0;

    system("cls");
    printf("-----------LOGIN INFO-----------\n");

    while (access==0)
    {
        printf("Enter username: \t");
        gets(user);

        printf("Enter pass: \t\t");
        gets(pass);

        if (strcmp(user,ADMINUSER) == 0 && strcmp(pass,ADMINPASS) == 0)
        {
            printf("\n-------Access Granted-------\n");
            access=1;
            Sleep(1000);
            printf("\nAccessing Menu...");
            Sleep(1500);
            checkGuest();

        }
        else
        {
            printf("\n-------Access Denied-------\n");
            Sleep(1000);
        }
    }

    system("cls");
    printf("\n\n\tThank you for using this program!\n\n\n");
    Sleep(5000);

    return 0;
}

//BRINGS UP GUEST INPUT MENU
void checkGuest()
{
    char guest[99];
    int in1, in2, in3;
    int out1, out2, out3;
    int room_num,rate,days,choice=1;
    float amount;

    while (choice!=0)
    {
        system("cls");
        printf("\n-----------Room Rates----------\n");
        printf("\nRoom 1 to Room 5 Single Room (Good For One Person)-\t Php200.00");
        printf("\nRoom 6 to 10 Double Room(Good for two people)-\t\t Php500.00");
        printf("\nRoom 11 to 15 Family Room (Good for 5 people)-\t\t Php900.00");
        printf("\n\n--------Accommodation---------\n");
        printf("\n- Rooms are fully airconditioned\n- Cable Television\n- Comfort Room and Shower with heater\n- Comfortable Beds that accomodates the respective number of people in each room\n- Room Service");

        printf("\n\n------------INPUT------------");
        printf("\n\nEnter Guest Name: ");
        gets(guest);

        printf("Date Of Check-In (MM/DD/YYYY): ");
        scanf("%d/%d/%d",&in1, &in2, &in3);

        printf("Date of Check-Out (MM/DD/YYYY): ");
        scanf("%d/%d/%d",&out1, &out2, &out3);

        rate=0;
        while (rate==0)
        {
            printf("Enter Room Number: ");
            scanf("%d",&room_num);

            if(room_num<=5)
                rate=200;
            else if(room_num<=10)
                rate=500;
            else if (room_num<=15)
                rate=900;
            else
            printf("Room does not exist\n");
        }

        printf("Displaying results...");
        Sleep(1000);

        system("cls");
        printf("\n----------Results----------");
        days=calculateDate(in1,in2,in3,out1,out2,out3);
        amount = days*rate;

        printf("\nGuest: \t\t");
        puts(guest);
        printf("Check-In: \t%d/%d/%d",in1, in2, in3);
        printf("\nCheck-Out: \t%d/%d/%d",out1, out2, out3);
        printf("\nDays staying: \t%d",days);
        printf("\nRoom Number: \t%d",room_num);
        printf("\nTotal: \t\tP%.2f",amount);

        Sleep(2000);
        printf("\n\nCalculate again?\n1-Yes 0-No");
        printf("\n\nChoice: ");
        scanf("%d",&choice);

        fflush(stdin);
    }

    return;
}

//CALCULATES THE DATE
int calculateDate(int m1, int d1,int y1,int m2,int d2,int y2)
{
    int days=0;
    int month,months[12]={31,28,31,30,31,30,31,31,30,31,30,31};

    if(y1==y2 && m1==m2)
    {
        days=d2-d1;
    }
    else
    {
        if (m2>m1)
        {
            month=m1;

            while (month<=m2)
            {
                days=months[month-1]+days;
                month++;
            }

            days=(days-(d1+(months[m2-1]-d2)));
        }
        else if (m1>m2)
        {
            month=m2;

            while (month<=m1)
            {
                days=months[month-1]+days;
                month++;
            }

            days=days-((months[m1-1]-d1)+d2);
        }

        if (y2 > y1)
        {
            int year=0;

            year=365*(y2-y1);

            if (m2>m1)
                days = year + days;
            else if (m2<m1)
 days="year" -="" days;
="" else="" if="" (m2="=m1" &&="" d1="">d2)
                days = year - (d1-d2);
            else if (m2==m1 && d2>d1)
                days = year + (d2-d1);
        }
    }
    return days;
}

What I have tried:

//Im kind of having a hard time changing the password into a changeable one as our prof asked us to put a forgot password feature. its in c programming
Posted
Updated 8-Jan-22 21:35pm
Comments
Richard MacCutchan 9-Jan-22 3:21am    
You should store all userid and password information in a file or database, rather than hard coding it in your program. You can then easily lookup the details and change them as necessary.
KarstenK 9-Jan-22 4:55am    
never ever write passwords in code. You will get grilled for that.

1 solution

OK, lots of things for you to think about here.
As Richard has said, userids and passwords shouldn't be hard coded: it's inflexible, and far, far too easy to just look in the EXE file and see what they are. So use a file to store them instead.

But file storage brings it's own problems: data protection comes into force here as passwords are considered "personal information" and by law in most countries need to be properly protected - which means salting and hashing them rather than storing them in clear text or encrypted, so they can't be "undone" and the original data recovered.
This explains the reasons and the basic process (though it's C# focused not C, it should be pretty obvious): Password Storage: How to do it.[^]

And remember: if you have any European Union users then GDPR applies and that means you need to handle passwords as sensitive data and store them in a safe and secure manner. Text is neither of those and the fines can be .... um ... outstanding. In December 2018 a German company received a relatively low fine of €20,000 for just that.

When that's dealt with, "forgotten passwords" can be dealt with - add a temporary password (randomly generated) to the account with an expiry date (normally 24 hours) and email that to the user, together with instruction on how to reach the "change password" part of your app. The user logs in with the temporary password you emailed to him, and changes it to one he can remember. This does require you to get a validated email address as part of your "sign up" procedure!
If the temporary password isn't used or changed before the expiry period runs out, it becomes invalid and is removed.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900