c++ - C++ 中的密码强度

标签 c++ password-encryption entropy

我正在用 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;
}

最佳答案

这个公式

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

总是生成 18,因为它根本不考虑密码的组成。它只考虑它的前七个字符的长度,总是 1*4+7*2=18。该标准根据密码的组成定义了不同的评估方法,即全低位/高位、低位+高位、低位+高位+数字等。

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

希望这对您有所帮助。

关于c++ - C++ 中的密码强度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21421676/

相关文章:

c++ 无法获取 "wcout"来打印 unicode,并让 "cout"继续工作

c++ - 使用已删除的函数错误

PostgreSQL 将密码加密从 SCRAM 降级到 md5

c++ - 生成具有一定熵的随机数序列

python - 如何消除两个数据集的 Leibler 分歧

c# - 你如何确保你的熵值

c++ - 如何在声明之外定义模板类的友元模板函数?

c++ - 用多个线程填充 vector

php - CodeIgniter 中的密码散列和验证

jquery - 使用 Hash sha-512 在数据库中使用加密密码验证表单中的密码