【问题标题】:Password Strength in C++C++ 中的密码强度
【发布时间】:2014-01-29 03:46:58
【问题描述】:

我正在用 C++ 制作一个小型密码强度计算器,它将计算密码的信息熵值以及 NIST 值。我有程序的熵部分工作,但 NIST 部分给了我一些问题。我很确定我有正确的公式,但是每次我输入测试密码时,我知道应该给我一个 24 的值,我得到一个 18 的值。我在我的代码中没有看到会导致这种情况的问题让我相信这是公式的问题。是否有人熟悉 NIST 公式并可以为我提供帮助?任何帮助将不胜感激。我在下面附上了我的代码。

#include <iostream>
#include <cmath>
#include <string>
using namespace std;

int main(){
  string eight_password, first_char, next_seven;
  int ep_length;
  double ent_strength, nist_strength;
  const int NIST_FIRST = 4, NIST_SEVEN = 2, NIST_REM = 1;
  const double NIST_TWELVE = 1.5; 
  cout << "Hello! Please enter a password of 8 characters or less (including spaces!):" << endl;
  getline(cin, eight_password);
  ep_length = eight_password.length();
  ent_strength = (ep_length*((log(94))/(log(2))));
  first_char = eight_password.substr(0, 1);
  next_seven = eight_password.substr(1, 7);
  nist_strength = (first_char.length()*NIST_FIRST) + (next_seven.length()*NIST_SEVEN);
  cout << nist_strength<<endl;
  cout << first_char.length() << endl;
  cout << next_seven.length() << endl;
  return 0;
}

【问题讨论】:

  • 如果您添加到规范的链接会提供帮助
  • Go Here 并向下滚动到“NIST Special Publication 800-63”

标签: c++ password-encryption entropy


【解决方案1】:

这个公式

nist_strength = (first_char.length()*NIST_FIRST) + (next_seven.length()*NIST_SEVEN);

总是产生 18,因为它根本不考虑密码的组成。它只考虑其第一个和接下来的七个字符的长度,始终为 1*4+7*2=18。该标准根据密码的组成定义了不同的评估方法,即全小/大、小+大、小+大+数字等。

我建议你设置两个变量n1和n7,根据标准检查前7个字符和后7个字符是什么后计算它们的值,然后在公式中使用。

希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-26
    • 1970-01-01
    • 2022-12-18
    相关资源
    最近更新 更多