c语言登入系统,c语言编写登录程序

发布时间:2022-11-24

本文目录一览:

  1. c语言设计用户登录系统,在登录界面中,如果第一次密码错误,第二次明明输入密码正确为什么还是显示错误
  2. 多用户登录系统C语言程序
  3. c语言登录系统

c语言设计用户登录系统,在登录界面中,如果第一次密码错误,第二次明明输入密码正确为什么还是显示错误

请把原码全部贴出来,这个截图太模糊。 我从模糊的图片中,看到类似fread的字样。那么你的账户密码信息是从一个文件中读取出来。 那么: 一、检查你文件中的原始数据是否有写错。 二、用于存储的变量空间是否够存储全部读取的数据。 三、对一个文件多次读写后,文件指针不在初始位置,确认是否需要fseek设置文件指针初始位置。 四、检查fopen是否执行成功。比如:多次fopen同一个文件,但前一次没有用fclose关闭文件流。

多用户登录系统C语言程序

#include stdio.h
#include stdlib.h
#include "string.h"
#include "windows.h"
int total=0;
struct u_p
{
    char user[20];
    char pass[20];
} s[50];
void read()
{
    total=GetPrivateProfileInt("INFO","count",0,"d:\\Info.dat");
    int i;
    char t[5]={"\\0"};
    for(i=0; i<total; i++)
    {
        sprintf(t,"%d",i+1);
        GetPrivateProfileString(t,"USER","",s[i].user,20,"d:\\Info.dat");
        GetPrivateProfileString(t,"PASSWORD","",s[i].pass,20,"d:\\Info.dat");
    }
}
void input()
{
    int p,i=0,count=0,f_u=0,f_p=0;
    char user[20]={"\\0"};
    char password[20]={"\\0"};
    while(1)
    {
        f_u=0;
        f_p=0;
        system("cls");
        printf("当前共有%d个注册用户",total); 
        printf("\n\n请输入用户名:");
        memset(user,'\\0',20);
        scanf("%s",user);
        printf("\n请输入密码:");
        memset(password,'\\0',20);
        i=0;
        while(1)
        {
            p=_getch();
            if(p==10 || p==13)
            {
                break;
            }
            password[i++]=p;
            printf("*");
        }
        for(i=0; i<total; i++)
        {
            if(strcmp(s[i].user,user)==0)
            {
                f_u=1;
                if(strcmp(s[i].pass,password)==0)
                {
                    f_p=1;
                    printf("\n\n欢迎 %s",user);
                    fflush(stdin);
                    _getche();
                    continue;
                }
            }
        }
        if(f_u==0)
        {
            printf("\n\n不存在该用户名! 选 1 重新输入,选 2 注册新用户");
            int c=0;
            fflush(stdin);
            c=_getche();
            if(c=='1')
            {
                continue;
            }
            else if(c=='2')
            {
                system("cls");
                printf("注册新用户");
                printf("\n\n\n请输入用户名:");
                memset(user,'\\0',20);
                scanf("%s",user);
                printf("\n请输入密码:");
                char temp[20]={"\\0"} ;
                i=0;
                while(1)
                {
                    p=_getch();
                    if(p==10 || p==13)
                    {
                        break;
                    }
                    temp[i++]=p;
                    printf("*");
                }
                printf("\n请再次输入密码:");
                i=0;
                memset(password,'\\0',20);
                while(1)
                {
                    p=_getch();
                    if(p==10 || p==13)
                    {
                        break;
                    }
                    password[i++]=p;
                    printf("*");
                }
                if(strcmp(temp,password)==0)
                {
                    total++;
                    char t[5]={"\\0"};
                    sprintf(t,"%d",total);
                    WritePrivateProfileString("INFO","count",t,"d:\\Info.dat");
                    WritePrivateProfileString(t,"USER",user,"d:\\Info.dat");
                    WritePrivateProfileString(t,"PASSWORD",password,"d:\\Info.dat");
                    printf("\n\n注册成功,请重新登录");
                    fflush(stdin);
                    _getch();
                    count=0;
                    read();
                    continue; 
                }
                else
                {
                    printf("\n\n两次密码不一致,注册失败");
                    fflush(stdin);
                    _getch();
                    count=0;
                    continue; 
                }
            }
        }
        else if(f_p==0)
        {
            count++; 
            if(count=3)
            {
                printf("\n\n连续输入3次错误,程序将退出");
                fflush(stdin);
                _getche();
                return ; 
            }
            printf("\n\n密码输入错误,请重新输入");
            fflush(stdin);
            _getche();
        }
    }
    return ;
}
int main(int argc, char *argv[]) 
{
    read();
    input();
    return 0;
}

c语言登录系统

#include stdio.h
#include string.h
#include stdlib.h //增加return的库函数
int login()
{
    char secercode[6];
    int number = 3;
    printf("\n\n\n");
    printf("\t\t**********欢迎使用管理系统**************");
    printf("\n\n");
    scanf("%s",secercode);
    while (number>0)
    {
        if (strcmp(secercode,"88888888")==0)
            return EXIT_SUCCESS; //while语句里面的结束循环用break是不对的
        else
        {
            number--;
            if(number<=0)break;
            printf("\t\t\t  还有%d次机会\n",number);
            printf("\n\t\t\t请输入密码: ");
            scanf("%s",secercode);
        }
    }
    if(number>0) return 1;
    else return 0;
}
mainMenu()
{
    printf("密码正确 \n");
}
main()
{
    if (login() == 0)return 1;
    do
    {
        mainMenu();
    }while(1);
}