Ⅰ 怎麼用c語言寫一個創建用戶名和密碼並且能修改密碼的程序
#include <stdio.h>//我自己做的,你拿去用吧!
#include <string.h>
struct e
{
char a[10];
char b[10];
}z;
int main()
{ int t=0;
char s[10],d[10];
FILE *p;
void as();
if ((p=fopen("m.txt","r+"))==NULL)
{
p=fopen("m.txt","w+");
t=1;
}
if(t==1)
{
printf("當前沒有任何用戶\n");
printf("請新建用戶名: ");
scanf("%s",s);
printf("為用戶設置密碼: ");
scanf("%s",d);
strcpy(z.a,s);
strcpy(z.b,d);
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
}
if(t==0)
{
printf("請輸入用戶名: ");
scanf("%s",s);
fscanf(p,"%s %s",z.a,z.b);
fclose(p);
if (!strcmp(z.a,s))
{
printf("請輸入密碼:");
scanf("%s",d);getchar();
if(!strcmp(z.b,d))
{ char i;
printf("是否要修改密碼?(輸入y修改,n退出!)");
scanf("%c",&i);
if(i=='y')
{
printf("請輸入修改密碼:");
scanf("%s",z.b);
p=fopen("m.txt","w+");
fprintf(p,"%s %s",z.a,z.b);
fclose(p);
printf("修改成功!");
}
}
else printf("密碼錯誤!");
}
else printf("用戶名錯誤");
fclose(p);
}
}
Ⅱ 用c語言生成八位的隨機密碼
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
char pool[]=
{
Ɔ',Ƈ',ƈ',Ɖ',Ɗ',Ƌ',ƌ',ƍ',Ǝ',Ə',
'a','b','c','d','e','f','g','h','i','j',
'k','l','m','n','o','p','q','r','s','t',
'u','v','w','x','y','z','A','B','C','D',
'E','F','G','H','I','J','K','L','M','N',
'O','P','Q','R','S','T','U','V','W','X',
'Y','Z'
};//隨機池
srand(time(0));
char pwd[9];
pwd[8]='