首先,我看到要使用CRYPT_BLOWFISH,我需要使用以$ 2a $开头的16个char盐.但是,crypt()的php.net文档说某些系统不支持CRYPT_BLOWFISH.这种情况多久一次?
接下来,从他们在docs上的例子中,我看到我使用crypt()如下:
<?php
$password = crypt('mypassword'); // let the salt be automatically generated
/* You should pass the entire results of crypt() as the salt for comparing a
password, to avoid problems when different hashing algorithms are used. (As
it says above, standard DES-based password hashing uses a 2-character salt,
but MD5-based hashing uses 12.) */
if (crypt($user_input, $password) == $password) {
echo "Password verified!";
}
?>
Run Code Online (Sandbox Code Playgroud)
为了使用CRYPT_BLOWFISH,我唯一需要修改的是第一行来使它像这样;
crypt('mypassword', '$2a$07$usesomesillystringforsalt$')
Run Code Online (Sandbox Code Playgroud)
然后剩下的线路都很好吗?
这些是我用于密码加密和密码验证的一些功能.想知道这是否是处理它的好方法.我正在使用codeigniter框架.
这是'加密'的功能:
function crypt_pass( $input ){
$salt = substr(sha1(date('r')), rand(0, 17), 22);
$cost = 10;
$hash = '$2y$' . $cost . '$' . $salt;
$pw_and_salt['pw'] = crypt($input, "$hash");
$pw_and_salt['salt'] = $salt;
return $pw_and_salt;
}
Run Code Online (Sandbox Code Playgroud)
我将密码和盐存储在我的数据库中.这是登录功能:
function login(){
$this->db->select('salt');
$salt = $this->db->get_where('users', array('username' => $this->input->post('username') ) )->row();
$where = array(
'username' => $this->input->post('username'),
'password' => crypt( $this->input->post('password'), '$2y$10$' . $salt->salt),
);
$user = $this->db->get_where('users', $where)->first_row();
if (!$user) {
return FALSE;
}else{
if(!empty($user->activation)){
return 2;
}else if($user && empty($user->activation)){
$this->session->set_userdata('id',$user->id);
$this->session->set_userdata('username',$user->username);
$this->session->set_userdata('first_name',$user->first_name); …Run Code Online (Sandbox Code Playgroud) 我确实对crypt()PHP函数感到困惑.
当第二个crypt明显使用不同的第二个参数时,以下两个crypt函数如何提供相同的输出?Diff salt意味着diff hash对吧?
echo crypt("password", '$2y$09$anexamplestringforsalt$')."\n<br>";
echo crypt("password", crypt("password", '$2y$09$anexamplestringforsalt$'))."\n<br>";
Run Code Online (Sandbox Code Playgroud)
输出:
$2y$09$anexamplestringforsale/.K.VdgECUVEd9N4ja3u1WtgPi5BXZq
Run Code Online (Sandbox Code Playgroud) echo crypt('test', "$2a$07$");在PHP版本5.4.16中生成一个长哈希,但它*0在5.6.4中生成"失败字符串" .
阅读关于crypt()的PHP文档,我仍然不太清楚为什么,尽管Changelog提到*1返回而不是*0取决于环境.(http://php.net/manual/en/function.crypt.php)
*0在这种情况下归还的原因是什么?PHP过去5.4是否停止容忍表单的坏盐$2a$07$?
crypt(text,"k7")
Run Code Online (Sandbox Code Playgroud)
我查了一下,显然'k7'是盐,但我不知道这意味着什么类型的输出将来自那个,谁都知道?
我有一个ruby客户端程序,用字符串#crypt加密密码,如此
encrypted = password.crypt(SALT)
# removing first two characters which actually are the salt for safety
return encrypted[2, encrypted.size - 2]
Run Code Online (Sandbox Code Playgroud)
然后将其发送到服务器以与其存储的预加密字符串进行比较.我怎么能够从ac#app和php网页发送相同的加密密码,并且仍然能够使用来自任何其他客户端的相同密码登录.
加密的C#和php中的等效代码是什么?
使用PHP crypt()方法我有一个PHP脚本来存储MySQL数据库中的用户加密密码.你能告诉我应该使用哪种字段来存储加密数据吗?
谢谢
预期结果:
该程序采用哈希密码作为输入; 这被传递给decrypt函数.该函数迭代每个混合大小写的n字母组合,对每个这样的字符串进行散列.如果找到与输入匹配的内容,则会打印出未散列的密码; 否则,它会退出.
实际结果:
函数仅针对当前迭代中的最后一个字母迭代每个混合大小写字母.
问题描述:
我正在尝试用Python实现一个简单的暴力DES加密密码破解程序.我使用了很多for循环实现了4个字符的密码实现,但现在我想使用递归来重构一段长度.如何迭代每个字符组合,从1-char组合到4个字符的字符串组合?
我想用这一行:
password[i] = string.ascii_letters[j]
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
TypeError: 'str' object does not support item assignment
Run Code Online (Sandbox Code Playgroud)
代码段:
def decrypt(encryptedText):
# reference global variable
global password
# check curr password guess length
pwdlen = len(password)
if pwdlen >= 4:
print("Password is longer than 4 characters, exiting...")
exit(2)
# debug lines
print("password is {}".format(password))
print("length: {}".format(pwdlen))
time.sleep(2)
# first two characters is salt
salt = encryptedText[:2]
# Check hashes for every combination of strings and compare them …Run Code Online (Sandbox Code Playgroud) 我正在为CS50做第2周的pset.当使用crypt函数时,指向任何字符串的密文的char指针总是指向我加密的最后一个东西.例如:
char password[] = "AAAA";
char toCrack[] = "AAzz";
printf("%s\n", password);
printf("%s\n", toCrack);
char *toCrackCiph = crypt(toCrack, "da");
char *passwordCiph = crypt(password, "aa");
printf("%s\n", passwordCiph);
printf("%s\n", toCrackCiph);
Run Code Online (Sandbox Code Playgroud)
toCrackCiph和passwordCiph彼此相等,即使它们的字符串不相同,也不是盐.
我在某处做了一个简单的指针错误吗?
谢谢,