gpt4 book ai didi

c - 创建帐户后用户无法登录

转载 作者:太空宇宙 更新时间:2023-11-04 00:11:10 25 4
gpt4 key购买 nike

我正在尝试自己用 C 语言开发一个简单的应用程序。它可以帮助任何人创建他/她的帐户并保存她的个人信息,这是安全的。直到现在用户可以创建他/她的帐户她而当用户返回登录时他不能。我已经编写并使用了文件 I/O 来保存用户凭据。

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

int main (int argc, string argv[])
{
// The pointer to the File
FILE* accountsDatabase = fopen("accountsDatabase.txt", "r+");

char Fdecision;
char Gateway = 'Y';
char Gatewaydenied = 'N';

string stringGateway = "Yes";
string stringGatewayDenied = "No";
string information;
string Newusername;
string Newpassword;
string Universalpassword;
string Universalusername;

printf("\n \t \n");

printf("\tThis is Dell login interference.....");
printf("\n");
printf("\t#################################\n");
printf("\t#################################\n");

printf("\n");
printf("\n");

printf(" Please inset your id and password in below user friendly interface.");
printf("\n");
printf("\n");

printf("Please type answer in Y and N");
printf("\n");
printf("Do you want the Dell's login user interfae: ");
Fdecision = GetChar();

if (Fdecision == Gateway)
{
printf("Do you want to create a new user. Answer in Yes or NO: ");
string userChoice = GetString();
printf("\n");
if (strcmp(stringGateway, userChoice) == 0)
{
printf("To create a New User Account.... Fill following boxes..\n");
printf("\n");
printf("username: ");
Newusername = GetString();
printf("password: ");
Newpassword = GetString();
printf("\n");
printf("Your personal textBook..:: ");
information = GetString();
printf("\n");
// Checks if it is opened..
if (accountsDatabase == NULL)
{
printf("Error opening file:\n");
}
else
{
fputs(Newusername, accountsDatabase);
fputs(Newpassword, accountsDatabase);
}
printf("Do you want to login.? Answer in Yes or No: ");
string LoginDecision = GetString();
if(strcmp(stringGateway, LoginDecision) == 0)
{
printf("Username: ");
string username = GetString();
printf("\n");
if (strcmp(Newusername, username) == 0)
{
printf("Password: ");
string password = GetString();
if (strcmp(Newpassword, Newpassword) == 0)
{
printf("\n");
printf("Confirming Identity.....\n");
printf("Identity Confirmed.....\n");
printf("\n");
printf("Do you want to reveal your sensitive information: ");
string secondDecision = GetString();
if (strcmp (stringGateway, secondDecision) == 0)
{
printf("\n");
printf("Enter password:: ");
string Currentpassword = GetString();
if (strcmp (Newpassword, Currentpassword) == 0)
{
printf("\n");
printf("%s\n", information);
printf("\n\n");
}
}
}
}
}
}
else if (strcmp(stringGatewayDenied, userChoice) == 0)
{
printf("\n");
printf("Username: ");
string username = GetString();
printf("\n");


// Checks if it is opened..
if (accountsDatabase == NULL)
{

printf("Error opening file:\n");
}
else
{
fgets(Universalusername, "%s", accountsDatabase);


if (strcmp(Universalusername, username) == 0)
{
printf("Password: ");
string password = GetString();

if (strcmp(Universalpassword, password) == 0)
{
printf("\n");
printf("Confirming Identity.....\n");
printf("Identity Confirmed.....\n");
printf("\n");
printf("Do you want to reveal your sensitive information: ");
string secondDecision = GetString();
if (strcmp (stringGateway, secondDecision) == 0)
{
printf("\n");
printf("Enter password:: ");
string Currentpassword = GetString();
if (strcmp (Universalpassword, Currentpassword) == 0)
{
printf("\n");
printf("%s\n", information);
printf("\n\n");
}
}

}
}
}
printf("Universalusername : %s", Universalusername);
}
else
{
printf("Take these security measures...\n");
printf("##############################");
printf("\n");
printf(" 1) You need specil previlage to access sensitive information...\n");
printf(" 2) Please run in a minute either alarm will be trigered..\n");
printf(" 3) Security camera are availabel, \n 4) run now.\n");
}

}
else if (Fdecision == Gatewaydenied)
{
printf("\n");
printf("You can get off from front door.\n");
printf("Don't LOok Back, it's not safe..\n'");
printf("What do you think? Can you cheat me? \n");
printf("No, you cannot!");
}

else
{
printf("\n");
printf("Please choose between Yes (Y) or No (N)\n");
printf("Not the full spelling but ony a single abbreviated letter..\n");
printf("Y or N..\n");
}

fclose(accountsDatabase);
}

最佳答案

您的代码不够清晰也不易阅读。为了帮助你,我写了这段代码,你可以在日常编码中使用它,它可以让你的生活更轻松。希望这能有所帮助。

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



input(char *prompt,char *buff);
int YesNoQuetion(char *prompt);

int main (void)
{
char firstname[50];
char lastname[50];
printf("This is a little code that will help you create a clean code\n\n");
printf("Please enter your first and last name\n");

input("First name",firstname);
input("Last name",lastname);

if (YesNoQuetion("Do you realy want to know?"))
{
printf("\nThat's good '%s, %s', you just pressed Yes\n",firstname,lastname);
}
else{
printf("\nYou answerd No, that is also good\n");;
}

return 0;
}

/*__________________________________________________________________________________
*/
int YesNoQuetion(char *prompt){
int r=0,c;
printf("%s (Y/N) : ",prompt);
while(1){
c=_getch();
if(c=='n' || c=='N' || c=='y' || c=='Y'){
printf("%c\x8",c);
r=c;
}else{
if( (c=='\n'||c=='\r') && r)
break;
r=0;
printf("%d\x8\x7",c);
}
}
printf("%s\n",(r=='y'|| r=='Y')?"Yes":"No");
return (r=='y'|| r=='Y');

}
/*__________________________________________________________________________________
*/
int input(char *prompt,char *buff){
printf("%s :\t",prompt);
return scanf("%s",buff);
}

/*__________________________________________________________________________________
*/

关于c - 创建帐户后用户无法登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33709290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com