这是我的程序:
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
int main()
{
std::string hash = crypt("asd123","$2a$13$IP4FT4gf123I5bT6o4123123123123nbEXFqo.Oa123");
std::cout << hash;
}
运行这个会导致错误
terminate called after throwing an instance of 'std::logic_error' what(): basic_string::_M_construct null not valid Aborted (core dumped)
但是如果我从 salt 中移除 $ 它运行正常。
最佳答案
错误消息告诉您 crypt
为给定的参数返回一个空指针。这很可能是它发出失败信号的方式。您需要检查一下。
您可以通过 (1) 查找该函数的文档以及 (2) 阅读它来了解有关 crypt
的更多信息。
例如,您可以用谷歌搜索“unistd crypt”。
碰巧文档在一个漂亮的表格中指定了您可以使用的有效字符集。
关于c++ - $ 符号导致程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38116594/