/**
获取随机密码
date的格式是年月日yymmdd,privatyKey为10位左右的字母数字组合串
1.需要返回8位纯数字
2.须使用date,privatyKey来生成
3.每次调用都是随机生成的(在date、privatyKey相同的情况下,返回的结果也要不同),尽量保证低重复率
**/
getPassword(date,privatyKey){
}
/**
检测密码
getPassword生成的密码可以通过检测,随便输入的密码通不过检测
**/
checkPassword(date,privatyKey,password){
}
有什么合适的算法?
The unavoidable problem: There are too few things that can be stored in an 8-digit number (
1e8 或 2^30
).So this method is almost completely resistant to exhaustion. The attacker only needs to fix the first 3 bits and exhaust the last 5 bits.
When using it, the algorithm itself must be kept secret, or restrictions such as the number of attempts must be added.
A variant that slightly increases the difficulty of exhaustion:
You can use a ready-made hash function (such as sha256) to act on
(date, pkey)
. The result is generally much more than 8 digits of pure numerical information. Divide this information into small pieces and return one piece randomly.Try using MD5
If you want to return different results every time, you can use TripleDes
But the result can only be an 8-digit pure number, which is enough
md5, openssl is relatively simple
The final solution is to take part of the value after hashing