改进:利用哈希表加密密码管理系统中的密码,改进密码管理系统

本文章源于本人github学生管理系统项目的某个想法:https://github.com/oyhxgo/Student-Performance-Management-System

该项目任在完善期

哈希函数,为了了解原理,我先写了一个大致设想

//最初设想
#include<bits/stdc++.h>
using namespace std;
const int base=131;//这里是将字符串看成的进制
int hash1(string str) {
	int ans=0;
	for(int i=0;i<str.size();++i) 
		ans=ans*base+(int)str[i];
	return ans;
}
int main(){
	string a="abcdefg",b;
	int ans=hash1(a);
	cout<<ans<<endl;
	cin>>b;
	if(hash1(b)==hash1(a))
		cout<<"good!";
	else
		cout<<"bad";
	return 0;
}

斯,然后我研究了正统的哈希函数

//初学哈希,返回值为size_t(%llu),竟然属于整型
#include<bits/stdc++.h>
using namespace std;
int main(){
	string a="123456",b;
	hash<string>hash1;
	cout<<hash1(a)<<endl;
	cin>>b;
	cout<<hash1(b)<<endl;
	if(hash1(a)==hash1(b))
		cout<<"good!";
	else
		cout<<"bad";
	return 0;
}

加密性还是差,加点盐吧

//尝试实现哈希加盐
//首先测试随机生成字符串函数
#include<bits/stdc++.h>
using namespace std;
string rand_str(const int len)  
{
	srand(time(NULL));              //以时间为种子;
	string str;                 
	char c;                    
	int i;                   
	for(i = 0;i < len;i ++)
	{
		c = 'a' + rand()%26;
		str.push_back(c);       /*push_back()是string类尾插函数。这里插入随机字符c*/
	}
	return str;                
}
int main()
{
	string str;                 
	str = rand_str(20);         
	cout << str << endl;  
	string a="123456",b;
	a.append(str);
	hash<string>hash1;
	cout<<hash1(a)<<endl;
	cin>>b;b.append(str);
	cout<<hash1(b)<<endl;
	if(hash1(a)==hash1(b))
		cout<<"good!";
	else
		cout<<"bad";

	return 0;
}

呦西,非常的好,尝试写入密码管理系统

#include <bits/stdc++.h>
#include <conio.h>
using namespace std;
#define MAX 1000//用户密码最长为1000
time_t t = time(nullptr); // 获取1970年到现在的毫秒数
struct tm* now = localtime(&t); // 把毫秒转换为日期时间的结构体
//用户的属性
typedef struct log {
	char username[MAX][MAX];//用户名
	size_t password[MAX];
	int num;
	char salt[MAX][MAX];
} user;
FILE *logfile;
//开始录入用户名和密码
void Inituser(user *&U) {
	U = new user;//分配空间
}
string rand_str(const int len)  //随机字符串生成(盐)
{
	srand(time(NULL));              //以时间为种子;
	string str;                 
	char c;                    
	int i;                   
	for(i = 0;i < len;i ++)
	{
		c = 'a' + rand()%26;
		str.push_b
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

凌乱的程序猿

谢谢大佬长这么好看还给我打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值