当前位置:首页 » 编程语言 » c语言密码

c语言密码

发布时间: 2023-01-06 05:06:51

c语言 修改密码初始密码为123456,密码包含数字和字母,数字必须大于2位

#include<stdio.h>
#include<string.h>
#include<ctype.h>
intmain()
{charpsw[21]="123456",t1[21],t2[21];
inti,n=0;
printf("请输入初始密码: ");
do
{gets(t1);
n++;
err=strcmp(t1,psw);
if(err)printf("初始密码错误!请重新输入! ");
}
while(err&&n<3);
if(strcmp(t1,psw))
{printf("密码错误,不能登录! ");
return0;
}
while(n<3)
{while(n<3)
{printf("请输入新密码: ");
gets(t1);
for(i=0;t1[i];i++)
if(isdigit(t1[i]))n++;
if(n<3)
{n=0;
printf("数字必须大于2位! ");
}
}
printf("请再次输入新密码: ");
gets(t2);
if(strcmp(t1,t2)==0)
printf("密码修改成功! ");
else
{printf("二次密码不一致! ");
n=0;
}
}
return0;
}

㈡ c语言密码核对

加了一个,while句,错了 可以继续输入~

#include <stdio.h>
#include <string.h>
int comp(char* code1, char* code2); //定义密码比较函数

int main(void)
{
char code1[20]={0,};
char code2[20]={0,};
int rt;
while(1)
{
printf("输入密码: "); //pw1
scanf("%s",code1);

printf("密码确认: "); //pw2
scanf("%s",code2);

rt = comp(code1,code2); // Call 比较函数
if(rt == 0)
{
printf("\n-恭喜!密码一直!\n\n");
break;
}
else
printf("\n-很遗憾!密码错了!\n\n");

memset(code1,0x00,sizeof(code1)); //清楚内容
memset(code2,0x00,sizeof(code2));
}

return 0;
}

int comp(char* code1, char* code2) //比较函数 构造
{
return strcmp(code1,code2);
}

㈢ c语言 密码输入

因为你不清空数组,input超过密码长度的值还保留在数组里面。给你详细举例,
当你输入超过密码长度hehe1234,你的input里面的数据就是{h,e,h,e,1,2,3,4...}这时候你再输入正确密码hehe123,前面的都被覆盖,但是4还保留在数组里面,你的input其实还是hehe1234,所以你不可能再得到正确密码。

㈣ 帮忙用C语言写一个密码

#include <stdio.h>

#define MAX_LENGTH 128
#define FILE_NAME "pwd.dat"
#define INIT_PWD "123456"

char pwd[MAX_LENGTH+1];

void Init ( void )
{
FILE *fp;
fp = fopen ( FILE_NAME, "r" );
if ( fp == NULL )
{
strcpy ( pwd, INIT_PWD );
}
else
{
fgets ( pwd, MAX_LENGTH, fp );
fclose ( fp );
}
}

void Login ( void )
{
char ch;
char tmp[MAX_LENGTH+1];
int pass = 1;
while ( pass )
{
puts ( "==================================\nPlease input your password!" );
scanf ( "%s", tmp );
pass = strcmp ( tmp, pwd );
}
}

void Edit ( void )
{
puts ( "Please input a new password!" );
scanf ( "%s", pwd );
}

void End ( void )
{
FILE *fp;
fp = fopen ( FILE_NAME, "w" );
if ( fp == NULL )
{
printf ( "Cannot save your password!\n" );
system ( "pause" );
}
else
{
fputs ( pwd, fp );
fclose ( fp );
}
}

int main ( void )
{
Init();
Login();
Edit();
End();
}

㈤ c语言实现密码加密

unsignedchar*encrypt(unsignedchar*psw,intenc){
intsum=0,i;
if(enc){
for(i=0;i<6;i++){
psw[i]-=15;
sum+=psw[i];
}
psw[6]=(unsignedchar)sum;
psw[7]=0;
}
else{
for(i=0;i<6;i++){
sum+=psw[i];
psw[i]+=15;
}
if((unsignedchar)sum!=psw[6]){
printf("Badpassword ");
psw[0]=0;
returnpsw;
}
else{
psw[6]=0;
}
}
for(i=0;i<3;i++){
unsignedchart=psw[i];
psw[i]=psw[5-i];
psw[5-i]=t;
}
returnpsw;
}

intmain()
{
unsignedcharpsw[128];
scanf("%s",psw);
printf("encodeto:%s ",encrypt(psw,1));
printf("decodeto:%s ",encrypt(psw,0));
return0;
}

㈥ C语言如何实现输入密码以星号显示

C语言中可采用getch()函数来实现输入密码字符时,不显示字符到终端上,这时,只需要显示出一个相应的*就可以达到效果了。参考代码及运行效果如下图:

㈦ 如何用C语言编写密码程序

1、用一个字符数组来存密码
再用一个字符数组接收你的输入,然后用strcmp
来比较,如果返回0则密码是正确的
2、例程:

#include"stdio.h"
#include"string.h"
intmain()
{
charmima[100]="YuanShi888";
charinput[100]={0};
printf("请输入密码:");
gets(input);
if(strcmp(mima,input)==0)
printf("恭喜你,密码正确! ");
else
printf("对不起,密码输入错误! ");

}

㈧ 请问,用C语言如何实现密码输入

c语言中可采用getch()函数来实现输入密码字符时,不显示字符到终端上,这时,只需要显示出一个相应的*就可以达到效果了。参考代码及运行效果如下图:

㈨ c语言密码

  1. 用什么替换?

  2. 暂时用小写加移位取?比如A加密成c,B加密成d,就是大写变小写后位置发生变化。



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

void EncodeString(char *str,int key)
{
int length,i;//length为传入字符串长度,i用作循环计数器
length=strlen(str);
for(i=0;i<length;i++)//对字符串中的每个字符依次进行加密
{
if(isupper(str[i]))//对大写字母加密
{
str[i]+=key%26;
if(str[i]>'Z')
{
str[i]-=26;
}
else if(str[i]<'A')
{
str[i]+=26;
}
}
else if(islower(str[i]))//对小写字母加密
{
if(str[i]+key%26<128){
str[i]+=key%26;
if(str[i]>'z')
{
str[i]-=26;
}
else if(str[i]<'a')
{
str[i]+=26;
}
}
else{str[i]-=26;str[i]+=key%26;}
}

}
}

void main()
{
char arr[50],buffer;//arr[50]用来接收字符串信息,buffer用来接收缓冲区中的回车
int key;//key为加密秘钥
printf("This program encodes messages using a cyclic cipher. ");
printf("To stop, enter 0 as the key. ");
while(1)//程序一直运行,直到输入密钥0为止
{
printf("Enter the key: ");
scanf("%d",&key);
scanf("%c",&buffer);
if(0==key)
{
break;//输入密钥为0,则退出程序
}
printf("Enter a message: ");
scanf("%s",arr);
scanf("%c",&buffer);
EncodeString(arr,key);
printf("Encoded message: %s ",arr);
}
}

热点内容
随机启动脚本 发布:2025-07-05 16:10:30 浏览:532
微博数据库设计 发布:2025-07-05 15:30:55 浏览:29
linux485 发布:2025-07-05 14:38:28 浏览:310
php用的软件 发布:2025-07-05 14:06:22 浏览:760
没有权限访问计算机 发布:2025-07-05 13:29:11 浏览:436
javaweb开发教程视频教程 发布:2025-07-05 13:24:41 浏览:716
康师傅控流脚本破解 发布:2025-07-05 13:17:27 浏览:246
java的开发流程 发布:2025-07-05 12:45:11 浏览:692
怎么看内存卡配置 发布:2025-07-05 12:29:19 浏览:288
访问学者英文个人简历 发布:2025-07-05 12:29:17 浏览:837