用C语言编写对应权限登陆和重新登陆或退出

用C语言编写对应权限登陆和重新登陆或退出,第1张

/*登陆*/

void log_in()

{

FILE *fp = NULL

char user_name[21] = {0}

char password[21] = {0}

int is_default_pass = -1

char in_user[21] = {0}

char in_pass[21] = {0}

char ch

fp = fopen("code", "rb")

if(fp)

{

fscanf(fp, "%s\n%s", user_name, password)

if(strcmp("admin", user_name) == 0

&&strcmp("123456", password) == 0)

{

is_default_pass = 1

}

else

{

is_default_pass = -1

}

}

if(!fp || is_default_pass == 1)

{

if(!fp)

{

strcpy(user_name, "admin")

strcpy(password, "123456")

fp = fopen("code"中纤渣, "wb")

fprintf(fp, "%s\n%s", user_name, password)

fclose(fp)

fp = fopen("code", "rb")

}

printf("系统中只有默认用户,请输入用户名:admin, 密码:123456\n")

}

log_in_window:

printf("***********************************************\n")

printf("*请输入用户名(最大不超过20字符或者十个汉字)\n")

printf("***********************************************\n用户名: ")

gets(in_user)

printf("***********************************************\n")

printf("*请输入密码(最大竖链不超过20字符或者十个汉字) \n")

printf("***********************************************\n密码: ")

gets(in_pass)

if(strcmp(in_user, user_name) == 0

&&strcmp(in_pass, password) == 0)

{

ptr_instance->is_authorization = 1

}

else

{

printf("卖悄用户名或密码错误,请重新输入!\n")

goto log_in_window

}

fclose(fp)

}

/*修改密码*/

void modify_pass()

{

FILE *fp = NULL

char in_user[21] = {0}

char in_pass[21] = {0}

char in_pass2[21] = {0}

char user[21] = {0}

char pass[21] = {0}

int i = 0

fp = fopen("code", "rb+")

if(!fp)

{

printf("can't modify the pass, no code file!\n")

return

}

log_in_check_window:

fscanf(fp, "%s\n%s", user, pass)

fseek(fp, 0, SEEK_SET)

printf("***********************************************\n")

printf("*请确认用户名 \n")

printf("***********************************************\n用户名: ")

gets(in_user)

printf("***********************************************\n")

printf("*请确认密码\n")

printf("***********************************************\n密码: ")

gets(in_pass)

if(strcmp(user, in_user) != 0 || strcmp(pass, in_pass) != 0)

{

if(i <3)

{

i++

printf("密码或用户名出错, 请重新输入!\n")

goto log_in_check_window

}

else

{

return

}

}

log_in_window:

printf("***********************************************\n")

printf("*请输入新用户名(最大不超过20字符或者十个汉字) \n")

printf("***********************************************\n用户名: ")

gets(in_user)

log_in_pass_again_window:

printf("***********************************************\n")

printf("*请输入新密码(最大不超过20字符或者十个汉字)\n")

printf("***********************************************\n密码: ")

gets(in_pass)

printf("***********************************************\n")

printf("*请确认新密码(最大不超过20字符或者十个汉字)\n")

printf("***********************************************\n密码: ")

gets(in_pass2)

if(strcmp(in_pass, in_pass2) != 0)

{

printf("密码两遍输入不同, 请重新输入!\n")

goto log_in_pass_again_window

}

if(in_user[0] == 0)

{

printf("用户名不能为空, 请重新输入!\n")

goto log_in_window

}

fprintf(fp, "%s\n%s\n", in_user, in_pass)

fputc(EOF, fp)

printf("密码成功修改!\n")

fclose(fp)

}

/*登陆主函数*/

void log()

{

char get_buf[10] = {0}

unsigned options = 0

log_main_window:

if(ptr_instance->is_authorization == 1)

{

printf("\t 已登录\n")

}

else

{

printf("\t 请登录\n")

}

printf("\t*************************\n")

printf("\t| 1 登陆 |\n")

if(ptr_instance->is_authorization == 1)

{

printf("\t-------------------------\n")

printf("\t| 2 登出 |\n")

printf("\t-------------------------\n")

printf("\t| 3 修改用户/密码 |\n")

}

printf("\t-------------------------\n")

printf("\t| 4 清屏 |\n")

printf("\t-------------------------\n")

printf("\t| 5 退出 |\n")

printf("\t*************************\n")

printf("\t-------------------------\n")

printf("\t请输入选项:")

gets(get_buf)

options = char2int(get_buf)

if(ptr_instance->is_authorization == -1 &&(options == 2 || options == 3))

{

system("cls")

printf("输入错误, 请重新选择!\n")

goto log_main_window

}

switch(options)

{

case 1:

system("cls")

if(ptr_instance->is_authorization == -1)

{

log_in()

system("cls")

goto log_main_window

}

else

{

printf("本系统同一时间只能一人登陆,请重新选择!\n")

goto log_main_window

}

break

case 2:

memset(get_buf, 0, 10)

printf("你确定登出吗?<y/n>:")

gets(get_buf)

if(get_buf[0] == 'y')

{

ptr_instance->is_authorization = -1

system("cls")

goto log_main_window

}

else

{

goto log_main_window

}

case 3:

system("cls")

modify_pass()

system("cls")

goto log_main_window

case 4:

system("cls")

goto log_main_window

case 5:

memset(get_buf, 0, 10)

printf("你确定退出吗?<y/n>:")

gets(get_buf)

if(get_buf[0] == 'y')

{

system("cls")

break

}

else

{

goto log_main_window

}

default:

printf("输入错误, 请重新选择!\n")

goto log_main_window

break

}

}

void main()

{

log()

}

C99下歼塌编译运行!

#include <stdio.h>

#include <string.h>

#include <time.h>

// Pauses for a specified number of milliseconds.

void do_sleep(clock_t wait) {

clock_t goal

goal = wait + clock()

while (goal >clock())

}

// correct username and password

const char* u = "admin"

const char* p = "悉乱123456"

int main(void)

{

int i = 0

while (1) {

printf("Login user:")

char user[255] = { 0 }

gets(user)

char pwd[255] = { 0 }

printf("Login password:"氏陆圆)

gets(pwd)

// match

if (0 == strcmp(user, u) &&0 == strcmp(pwd, p)) break

if (++i >= 3) {

puts("Please retry after 10 seconds")

do_sleep((clock_t)10 * CLOCKS_PER_SEC)

i = 0

}

}

puts("Login success")

return 0

}

#include<stdio.h>

void main()

{

char name

int code

bool b=true

while(b)

{

printf("\n请输入用户名:")

scanf("%s"喊陆渗,&name)

printf("\n请输入密码:"郑脊)

scanf("%d",&code)

if(name=='h'&&code==0)

{

printf("欢迎光临\n")

b=false

}

else{

printf("重新登录\n")

}

}

}

希悉轮望对你有所帮助,不明白hi我。。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12264211.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-24
下一篇 2023-05-24

发表评论

登录后才能评论

评论列表(0条)

保存