我想拥有一种可以生成哈希字符串的哈希算法,但具有字母数字字符,但要在指定的限制下。
例如,如果我提供一些文本,则应生成一个可以用作网站密码的字符串。因此,至少8个字符必须至少包含一个大写字母和至少一个数字。
有这样的哈希算法吗?还是我必须创建自定义实现?还是根本不可能?
我想在JavaScript中这样做
I would like to have a hashing algorithm, that can generate a hash string but with alphanumeric characters but under a specified limit.
For example, If I provide it some text, it should generate a string that can be used as a password for websites. So at least 8 characters long, must contain at least a capital letter and at least a number.
Is there any hash algorithm like this? or would I have to create a custom implementation? or is it not possible at all?
I'd like to do this in javascript
发布评论
评论(2)
生成一个随机整数,该整数确定大写字母的数量,使用
getrandomint
从此答案使用采样与拒绝。这使用getrandomvalues
to 。让capnum = getrandomint(1,7)
一个保留用于数字的人
生成数字的数量。
让dignum = getrandomint(1,8-capnum)
现在我们有
8 -capnum -dignum -dignum
金额字母(不是Capitals)为每个组生成必要的随机元素,然后将它们全部存储到字符串
arr
。 P>应用“ nofollow noreferrer”> fisher -yates shuffle 算法字符串中的字符。
Generate a random integer that determines the number of capitals, Use
getRandomInt
from this answer that uses sampling with rejecting. This uses thegetRandomValues
to get cryptographically strong random values.let capNum = getRandomInt(1,7)
One reserved for digits
Generate the number of digits.
let digNum = getRandomInt(1, 8-capNum)
Now we have
8 - capnum - digNum
amount letters ( not capitals)Generate necessary random elements for each group and store all of them into a string
arr
.Apply Fisher–Yates shuffle algorithm so that the order of the characters in the string shuffles.
我没有说您需要哪种语言。
在csharp中:
I didn't say in which language you need the algorithm .
In CSharp: