C语言实现随机密码、密钥的生成

功能介绍:该程序可以生成密码字符库pwdcont中字符随机组合,长度范围在6-63的密码、密钥

说明:密码字符库和密码的长度范围可自行更改

源码:

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
#include <windows.h>

char pwdcont[]="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_";
 
char* GeneratePassword(int pwd_size)
{
	int i; 
	int random;
	char *Password = (char *)malloc(pwd_size + 1);
	
	srand((unsigned)time(NULL));
	for(i = 0;i < pwd_size;i++)
	{
        random = rand()%(strlen(pwdcont));
		*(Password + i) = pwdcont[random]; 
	}
	
	*(Password + i)= '\0'; 
	return Password;	
} 

int main()
{
    int random;
    char *Password;
	srand((unsigned)time(NULL));
    
	for(int i=0;i<10;i++)
	{
		Sleep(100);
        random=rand()%(58)+6;//密码的长度范围 (6-63) 
        printf("random = %d\n",random);
		Password = GeneratePassword(random); 
		printf("Password = %s\n",Password);
	}
	free(Password);
	return 0;
} 

运行结果:
在这里插入图片描述

  • 3
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值