【问题标题】:Is there an existing algorithm in checking password strength? Or re-invent the wheel?是否有检查密码强度的现有算法?还是重新发明轮子?
【发布时间】:2015-12-03 01:20:18
【问题描述】:

我一直在考虑开发一个 Android 应用程序,它会告诉用户输入密码的密码强度。

在检查密码强度方面,我开发了这 2 个算法 来检查它。但我正在考虑使用这些算法,因为我认为它效率不高。 大家觉得呢?

这是我的 2 个算法:

平均法

Sample input = Password12@

1. Count the lowercase, uppercase, digits and special characters in the given String.
   Eg.
   Lowercase count = 7;
   Uppercase count = 1;
   Digits count = 2;
   SpecialCharacter count = 1;

2. Get the character count and multiply it to the size of given String.
   Eg.
    (Count * Size)
    (7 * 10) = 70
    (1 * 10) = 10
    (2 * 10) = 20
    (1 * 10) = 10

3. Add the following results
   Eg.
    70 + 10 + 20 + 10 = 110

4. Get the results which is the password strength.
   Eg.
    The password is 110% strong.

积分法

Sample input = Password12@

1. Set the points such that for every:
    Lowercase = 1 point given
    Uppercase = 5 points given
    Digits = 10 points given
    Special Character = 15 points given

2. Count the lowercase, uppercase, digits and special characters in the given String.
   Eg.
   Lowercase count = 7;
   Uppercase count = 1;
   Digits count = 2;
   SpecialCharacter count = 1;

3. Get the character count and add it to the given point and multiply the size of the given String.
   Eg.
    (Count + Point) * size
    (7 + 1) * 10 = 80;
    (1 + 5) * 10 = 60;
    (2 + 10) * 10 = 120;
    (1 + 15) * 10 = 160;

4. Add the following results and divide it to the size of given String and divide it by 4.
   Eg.
    //4 because count={uppercase, lowercase, digits, special character}
    80 + 60 + 120 + 160 = 420
    420 / 4 = 105

5. Get the result which is the pswword strength.
   Eg.
   The password strength is 105%.

我的问题是:

  • 哪种算法显示出更好的实现方式?

  • 如果 2 种给定算法效率低下,是否有现有算法可用于检查给定密码的强度。不是这样,重新发明轮子。

【问题讨论】:

    标签: passwords password-policy password-checker


    【解决方案1】:

    在检查密码强度时,您的两种算法都存在一些固有问题:

    第一个算法基本上只是计算密码的长度并乘以 10。使用此算法,密码“passwordpassword”将获得 160% 的评级。这么简单的密码太强了。

    第二种算法稍微复杂一些,并根据字符类型使用权重。但是,使用此算法,密码“1234”将获得 100% 的评级。我确定这不是您想要的。

    一般的经验法则是根据规则列表测试密码强度,然后对这些规则进行加权(连同密码实际执行的规则数量):

    • 密码长度必须至少为 8 个字符(10 pts)
    • 密码必须至少包含一个小写字母(5 分)
    • 密码必须至少包含一个大写字母(5 分)
    • 密码必须至少包含一个数字(5 分)
    • 密码必须至少包含一个符号(10 分)
    • 密码必须包含至少 5 个唯一字符(5 分)

    然后,您可以将强制执行的规则相加,并将该数字乘以强制执行的规则数乘以权重。例如:

    “1234” = (5) + 1*10 = 15

    “密码” = (5+5) + 2*10 = 30

    “密码1” = (5+5+5) + 3*10 = 45

    “密码1234” = (5+5+5+10) + 4*10 = 65

    “密码1234” = (5+5+5+5+10) + 5*10 = 80

    “密码@rd1234” = (5+5+5+5+10+10) + 6*10 = 100

    这只是对基于规则的方法如何工作的简单表述。就个人而言,我会以指数方式加权使用的规则数量,并且有各种各样的规则。基本上,满足的规则越多,密码越复杂,就越安全。

    【讨论】:

    • 先生,你从哪里得到的 10 号?
    • @camelCase 它只是一个基于我使用的其他值的随机数。它只是用来说明方法。如果你使用例如在我的示例中为 50 或 100 而不是 10,那么为每个单独规则给出的值将太低且不重要。它需要平衡。更高的单个规则值当然应该反映更高的“使用的总规则”权重。
    • 我知道!谢谢@Dryborg 很好的解释你到了那里
    【解决方案2】:

    开源密码强度检查器的链接:

    https://github.com/dropbox/zxcvbn

    我没用过,只是在google上找到的,看看。

    您的算法似乎没有很好地完成工作。

    第一个可以表示为字符数n^2,字符的种类没有区别。

    第二个是类似的,它仍然不意味着你输入什么样的字符,因为点只构成方程中的一个常数项: (d + 10) * 10 = d * 10 + 100(对于数字)。这不是更好,它只是显示更高的分数。

    两种算法都会产生一个大约是密码长度的平方的数字,而破解它的时间(或强度)更多地取决于长度的指数。

    从编码恐怖中查看这篇文章:http://blog.codinghorror.com/your-password-is-too-damn-short/

    破解随机密码的时间(来自文章):

    • 9 个字符 2 分钟
    • 10 个字符 2 小时
    • 11 个字符 6 天
    • 12 个字符 1 年
    • 13 个字符 64 岁

    random.org 生成器“只有”大写、小写和数字

    【讨论】:

      猜你喜欢
      • 2012-10-05
      • 2020-02-14
      • 2023-03-14
      • 1970-01-01
      • 2014-10-26
      • 2010-09-09
      • 1970-01-01
      • 2023-04-10
      • 1970-01-01
      相关资源
      最近更新 更多