当前位置:首页 » 编程语言 » c语言密码安全菜单
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

c语言密码安全菜单

发布时间: 2022-05-29 03:50:36

A. c语言密码程序

用一个文本文件或小数据库存储这些东西,比如,XML或SQLIITE等等,也可以用普通文本,存储进去之后,下次打开输入的时候,和新存入的密码进行匹配,如果没有匹配成功,失败。另外,为了密码的安全问题,一般会有一个MD5或者其他SHA算法进行加密下

B. c语言程序设计 密码设置程序怎么编写

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

int main(int argc,char *argv[])
{
const char user[]="wangpin";/*用户名自己可改动*/
const char password[]="wangpin@126";/*密码自己可改动*/
if(argc == 1)
{
printf("Input error! Usage:filename username password\n");
getch();
exit(1);
}
else if(argc == 3)
{
if (strcmp(argv[1],user) != 0 || strcmp(argv[2],password) != 0)
{
printf("Input error: Invalid username or password\n");
getch();
exit(1);
}
}
printf("Authentication Pass..\n");
sound(500);/*最简单的音乐声*/
delay(50000);
nosound();
getch();
return 0;
}

先运行这个程序得到一个exe类型的可执行文件,然后可以复制到c盘根目录下,用桌面左下的图标进入:开始-程序-附件-命令提示符
然后键入 cd \
到c盘根目录下输入
exe文件名 wangpin wangpin@126
就是运行这个程序
------------------------------------------------------------------
------------------------------------------------------------------
下面是一个简单的音乐程序,你可以把它加到上面代替sound()到nosound()那一部分发出<<东方红>>音乐歌曲(小心!声音可能很大)
#include <stdio.h>
#include <stdlib.h>
#include <dos.h>

int main(void)
{
int i,j;
int fr[]={392,392,440,294,262,262,220,294,392,392,
440,532,440,392,262,262,220,294,392,294,
262,247,220,196,392,294,330,294,262,262,
220,294,330,294,262,294,262,247,220,196};
int tim[]={4,2,2,8,4,2,2,8,4,4,2,2,2,2,4,2,2,8,4,
4,4,2,2,4,4,4,2,2,4,2,2,2,2,2,2,2,2,2,2,12};
for(i=0;i<40;i++)
{
sound(fr[i]);
delay(tim[i]*100000000);
nosound();
}
system("pause");
return 0;
}

C. 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;
}

D. 将凯撒密码X的加密、解密过程用C语言编程实现

1、在密码学中,恺撒密码(或称恺撒加密、恺撒变换、变换加密)是一种最简单且最广为人知的加密技术。它是一种替换加密的技术,明文中的所有字母都在字母表上向后(或向前)按照一个固定数目进行偏移后被替换成密文。例如,当偏移量是3的时候,所有的字母A将被替换成D,B变成E,以此类推。这个加密方法是以恺撒的名字命名的,当年恺撒曾用此方法与其将军们进行联系。恺撒密码通常被作为其他更复杂的加密方法中的一个步骤,例如维吉尼尔密码。恺撒密码还在现代的ROT13系统中被应用。但是和所有的利用字母表进行替换的加密技术一样,恺撒密码非常容易被破解,而且在实际应用中也无法保证通信安全。例子恺撒密码的替换方法是通过排列明文和密文字母表,密文字母表示通过将明文字母表向左或向右移动一个固定数目的位置。

2、kaiser加密算法具体程序:

#include<stdio.h>
#include<conio.h>
charencrypt(charch,intn)/*加密函数,把字符向右循环移位n*/
{
while(ch>='A'&&ch<='Z')
{
return('A'+(ch-'A'+n)%26);
}
while(ch>='a'&&ch<='z')
{
return('a'+(ch-'a'+n)%26);
}
returnch;
}
voidmenu()/*菜单,1.加密,2.解密,3.暴力破解,密码只能是数字*/
{
clrscr();
printf(" =========================================================");
printf(" 1.Encryptthefile");
printf(" 2.Decryptthefile");
printf(" 3.Forcedecryptfile");
printf(" 4.Quit ");
printf("========================================================= ");
printf("Pleaseselectaitem:");
return;
}
main()
{
inti,n;
charch0,ch1;
FILE*in,*out;
charinfile[20],outfile[20];
textbackground(BLACK);
textcolor(LIGHTGREEN);
clrscr();
sleep(3);/*等待3秒*/
menu();
ch0=getch();
while(ch0!='4')
{
if(ch0=='1')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要加密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputthekey:");
scanf("%d",&n);/*输入加密密码*/
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入加密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
while(!feof(in))/*加密*/
{
fputc(encrypt(fgetc(in),n),out);
}
printf(" Encryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='2')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputthekey:");
scanf("%d",&n);/*输入解密密码(可以为加密时候的密码)*/
n=26-n;
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
while(!feof(in))
{
fputc(encrypt(fgetc(in),n),out);
}
printf(" Decryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
if(ch0=='3')
{
clrscr();
printf(" Pleaseinputtheinfile:");
scanf("%s",infile);/*输入需要解密的文件名*/
if((in=fopen(infile,"r"))==NULL)
{
printf("Cannotopentheinfile! ");
printf("Pressanykeytoexit! ");
getch();
exit(0);
}
printf("Pleaseinputtheoutfile:");
scanf("%s",outfile);/*输入解密后文件的文件名*/
if((out=fopen(outfile,"w"))==NULL)
{
printf("Cannotopentheoutfile! ");
printf("Pressanykeytoexit! ");
fclose(in);
getch();
exit(0);
}
for(i=1;i<=25;i++)/*暴力破解过程,在察看信息正确后,可以按'Q'或者'q'退出*/
{
rewind(in);
rewind(out);
clrscr();
printf("========================================================== ");
printf("Theoutfileis: ");
printf("========================================================== ");
while(!feof(in))
{
ch1=encrypt(fgetc(in),26-i);
putch(ch1);
fputc(ch1,out);
}
printf(" ======================================================== ");
printf("Thecurrentkeyis:%d ",i);/*显示当前破解所用密码*/
printf("Press'Q'toquitandotherkeytocontinue...... ");
printf("========================================================== ");
ch1=getch();
if(ch1=='q'||ch1=='Q')/*按'Q'或者'q'时退出*/
{
clrscr();
printf(" GoodBye! ");
fclose(in);
fclose(out);
sleep(3);
exit(0);
}
}
printf(" Forcedecryptisover! ");
fclose(in);
fclose(out);
sleep(1);
}
menu();
ch0=getch();
}
clrscr();
printf(" GoodBye! ");
sleep(3);
}

E. C语言 密码设置

WINDOWS操作系统:

//---------------------------------------------------------------------------

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

int main(void)
{
char c;
while ((c=getch())!='q')
putchar('*');
return 0;
}
//---------------------------------------------------------------------------

LINUX操作系统:

//---------------------------------------------------------------------------

#include <curses.h>

int main(void)
{
initscr();

cbreak();
noecho();
while (getch()!='q') addch('*');
echo();
nocbreak;

endwin();
return 0;
}

/*编译时要加上 -lcurses 参数*/
//---------------------------------------------------------------------------

F. C语言 问题 E: 安全的密码

#include <stdio.h>

#include <string.h>

#include <ctype.h>


int main() {

int M, U, L, D, S;

char code[51];

char ch[] = "~!@#$%^";

scanf("%d", &M);

getchar();

while (M--) {

U = L = D = S = 0;

scanf("%s", code);

int len = strlen(code);

if (len < 8 || len > 16) {

printf("NO ");

continue;

}

int i = 0;

while (code[i] != '') {


if (isupper(code[i])) U++;

else if (islower(code[i])) L++;

else if (isdigit(code[i])) D++;

else {

int pos = strchr(ch, code[i]) - ch;

if (pos >= 0 && pos <= 7)

S++;

}

i++;

}

if (((U >= 1) + (L >= 1) + (D >= 1) + (S >= 1)) >= 3)

printf("YES ");

else

printf("NO ");

}

return 0;

}

G. C语言中,如何进行口令检查,后显示菜单

大概类似于(假定你的密码是123456)
char pwd[50];
printf("请输入密码:");
gets(pwd);
while(strcmp (pwd,"123456") != 0 )

{
printf("密码错误,请重新输入密码:");
gets(pwd);

}
//显示你的菜单

H. C语言 安全的密码 问题

写了个命令行版本的, 使用的时候, 直接把密码当成命令行参数使用吧,

如果不合心意, 可以自己改改(对于第4类字符, 没有考虑符号表)

/*
@20140129
for

by'热心网友'
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#definePASS_SAFE_NONE0
#definePASS_SAFE_LOW1
#definePASS_SAFE_MED2
#definePASS_SAFE_HIG3


intchkpasswd(char*pass);
intoutput(intsafecode);

intmain(intargc,char**argv){
if(argc!=2){
printf("UsageError ");
exit(1);
}
intret=chkpasswd(argv[1]);
output(ret);
}

intoutput(intcode){
printf("code=%d ",code);
switch(code){
casePASS_SAFE_NONE:
casePASS_SAFE_LOW:
printf("NotSafe ");
break;
casePASS_SAFE_MED:
printf("MediumSafe ");
break;
casePASS_SAFE_HIG:
printf("Safe ");
break;
}
returncode;
}

intchkpasswd(char*pass){
intlen=strlen(pass);
if(len<6)returnPASS_SAFE_NONE;

intb_class1=0;
intb_class2=0;
intb_class3=0;
intb_class4=0;
intret=0;

char*p=pass;
for(p=pass;p<(pass+len);p++){
if(ret>=PASS_SAFE_HIG)returnPASS_SAFE_HIG;

if(*p>='0'&&*p<='9'){//0-9
if(b_class1){
continue;
}else{
b_class1=1;
ret++;
}
}elseif(*p>='A'&&*p<='Z'){//Upper
if(b_class2){
continue;
}else{
b_class2=1;
ret++;
}
}elseif(*p>='a'&&*p<='z'){//Lower
if(b_class3){
continue;
}else{
b_class3=1;
ret++;
}
}else{//Symb
if(b_class4){
continue;
}else{
b_class4=1;
ret++;
}
}
}
returnret;
}

I. c语言 密码设置问题

scanf中的\n去掉
使用文件操作,把修改后的密码保存在文件中每次程序启动时读取该文件,获得密码.当然文件中的密码可以是加密后的值,不考虑安全性的话,也可以是明文的

J. C语言问题,怎么给系统设置一个密码

void main(){
int menunum; //
char c;
int count=0;
do{
char inputs[10]; //
printf("输入你的密码: "); //
scanf("%s",inputs); //

if(strcmp(inputs,"password")==0) //自己设置密码为password {
printf("\n\t\t\t 人口信息管理系统(可输入汉字)\n");
printf(" |^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^|\n");
printf(" |1、输入人口数据\t\t2、修改人口数据\t\t3、查找 |\n");
printf(" |4、排列人口数据\t\t5、打印人口信息\t\t6、删除人口数据|\n");
printf(" |7、备份文件 \t\t8、恢复文件 \t\t9、清除已删数据|\n");
printf(" |0、结束程序 \t\t\t\t\t |\n");
printf(" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \n");
printf("\n 操作方式:");
scanf("%d",&menunum);
switch(menunum)
{
case 0:return;
case 1:{CreatPeople();break;}
case 2:{ChangePeople();break;}
case 3:{Find();break;}
case 4:{SortPeople();break;}
case 5:{PrintPeople();break;}
case 6:{DeletePeople();break;}
case 7:{BackPeople();break;}
case 8:{UpPeople();break;}
case 9:{ClearPeople();break;}
default: //switch中要加default的条件保证程序的健壮性
break;
}
printf("按回车键继续\n");
c=getchar();c=getchar();
//system("cls");/*清屏*/
}
else //该保证三次输入错误即程序结束
{
count++; //要初始化
if(count==3)
{
break;
return;
}
}
}while(1);
return;
}