简体   繁体   English

对数字密码进行排名的算法?

[英]Algorithm to rank numeric passcode?

I'm studying a (mobile) app where I need to get a user PIN: a numeric "passcode" of 6/8 ciphers, input with something like this UI: 我正在研究一个(移动)应用程序,我需要获取用户PIN:6/8密码的数字“密码”,输入类似这样的UI:

密码mokup

So, in a registration step, the user configure his one passcode (as it would be a password). 因此,在注册步骤中,用户配置他的一个密码(因为它将是密码)。

Let say the passcode must have a fixed size (say 8 ciphers: ********) 假设密码必须具有固定大小(比如8个密码:********)

My question is related to a possible algorithm to verify/check the number that user choose, giving a bad rank in case of repeated ciphers or standard cipher patterns ( 12345678 , 00001111 ), easily predicible by a malicious crackers... 我的问题与可能的算法有关,用于验证/检查用户选择的数量,在重复密码或标准密码模式( 12345678 )的情况下给出不良排名, 00001111恶意破解者轻松预测......

Any idea for such an algorithm ? 对这样的算法有什么想法吗?

At firs glance the algorithm could discourage (bad rank) a passcod containing repeated ciphers, simething like: 在第一眼看来,算法可能会阻止(排名不好)包含重复密码的密码,如:

00117788
88886611 

or "usual" ascending/descending patterns as: 或“通常”上升/下降模式为:

12345678
98765432

Or numeric patterns related to personal, by example in my case, I'm born in 02 September 1963, so it could be a bad idea to have as passcode: 或者与个人相关的数字模式,例如在我的情况下,我出生于1963年9月2日,所以使用密码可能是一个坏主意:

02091963

Instead, sequence that appear to me as "good" could be by example these one: 相反,在我看来“好”的序列可以是这样的例子:

18745098 
90574808
07629301

Collateral question: do you think that a numeric passcode of let say 8 ciphers could be an acceptable solution as "password" to validate a payment transaction ? 附带问题:您是否认为使用8个密码的数字密码可以作为验证付款交易的“密码”的可接受解决方案?

BTW, I'm coding in Ruby. 顺便说一下,我用Ruby编写代码。

thanks for your patience! 谢谢你的耐心!

giorgio 乔治

For your first 2 cases: 对于前2个案例:

Number of repeated consecutive characters in the string: 字符串中重复的连续字符数:

str = "00117788"
str.chars.each_cons(2).select {|a,b| a == b}.count
#=> 4

Or as @CarySwoveland pointed out this will have the same result 或者@CarySwoveland指出这将有相同的结果

str.size - str.squeeze.size
#=> 4

Number of incremented characters 递增的字符数

str = "12345678"
str.chars.map(&:to_i).each_slice(2).select {|a,b| (a + 1) == b || (a - 1) == b }.count
#=> 4
#note this will also return 4 for "12563478"
# you could also use str.chars.map(&:to_i).each_cons(2).select {|a,b| (a + 1) == b || (a - 1) == b }.count
# This will return 7 for "12345678" and still return 4 for "12563478"

You could combine the above 2 as well like 你可以将上面的2组合起来

str = "00117788"
str.chars.map(&:to_i).each_cons(2).select {|a,b| (a + 1) == b || (a - 1) == b || a == b }.count
#=> 6

As for the "personal" issue if you have the birth day then something as simple as this should work: 至于“个人”问题,如果您有出生日那么简单的事应该起作用:

require 'date'
birth_day = Date.new(1963,9,2)
str = "02091963"
str == birth_day.strftime("%d%m%Y")
#=> true

Although for the last one I would suggest comparing multiple formats eg %Y%m%d and %m%d%Y etc. you could even do something like 虽然对于最后一个,我建议比较多种格式,例如%Y%m%d%m%d%Y等。你甚至可以做类似的事情

str.chars.sort == birth_day.strftime("%d%m%Y").chars.sort
#=> true

To make sure they don't just use those numbers in some jumbled format. 确保他们不只是以某种混乱的格式使用这些数字。

Hopefully this would get you started since I don't know what your thresholds are for "good" and "bad" these are just suggestions for checking the values. 希望这会让你开始,因为我不知道你的阈值是什么“好”和“坏”这些只是检查值的建议。 Although it seems the definition for "good" should just be not "bad". 虽然看起来“好”的定义应该不是“坏”。 Sort of like a validity check. 有点像有效性检查。

If I were to suggest a score of < 4 using methods 1 and 2 (or the combination method) && not an assortment of birth_day numbers would probably be sufficient eg 如果我使用方法1和2(或组合方法)建议<4的分数&&而不是各种各样的birth_day数字可能就足够了例如

def tester(str,birth_date)
  return false if ![6,8].include?(str.size)
  b_day = birth_date.strftime("%Y%m%d").chars.sort
  str.chars.map(&:to_i).each_cons(2).select  do |a,b| 
    (a + 1) == b || 
    (a - 1) == b || 
    a == b 
  end.count < 4 && b_day != str.chars.sort
end
tester("00112233",Date.new(1963,9,2))
#=> false
tester("18745098",Date.new(1963,9,2))
#=> true

Seems like it works with your examples 似乎它适用于您的示例

arry = ["00117788","88886611","12345678","98765432","02091963","18745098","90574808","07629301"]
Hash[arry.map{|v| [v,tester(v,Date.new(1963,9,2))]}]
#=>=> {"00117788"=>false, "88886611"=>false, 
       "12345678"=>false, "98765432"=>false, 
       "02091963"=>false, "18745098"=>true, 
       "90574808"=>true, "07629301"=>true}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM