标签: crypt

(PHP)如何在CRYPT_BLOWFISH中使用crypt()?

首先,我看到要使用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)

然后剩下的线路都很好吗?

php crypt

4
推荐指数
1
解决办法
1万
查看次数

Crypt()salt生成和密码加密,执行得很好?

这些是我用于密码加密和密码验证的一些功能.想知道这是否是处理它的好方法.我正在使用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)

php mysql crypt codeigniter salt

4
推荐指数
1
解决办法
6077
查看次数

如何在PHP中使用crypt($ pass,'$ 2y $ 09 $ salt')=== crypt($ pass,crypt($ pass,'$ 2y $ 09 $ salt'))?

我确实对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)

php hash crypt blowfish

4
推荐指数
1
解决办法
929
查看次数

PHP crypt()在5.6.4版本中返回*0失败字符串,但不是5.4,

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$

php crypt php-5.4 php-5.6

4
推荐指数
1
解决办法
1712
查看次数

crypt()在C中做了什么?

crypt(text,"k7")
Run Code Online (Sandbox Code Playgroud)

我查了一下,显然'k7'是盐,但我不知道这意味着什么类型的输出将来自那个,谁都知道?

c crypt

3
推荐指数
2
解决办法
2万
查看次数

Ruby#string在c#和php中加密

我有一个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 c# ruby string crypt

3
推荐指数
1
解决办法
1461
查看次数

为什么MySQL的ENCRYPT会在每次调用时返回不同的结果?

我有一个丑陋的服务器问题,我试图不忽略任何细节.

我的虚拟电子邮件用户密码存储在MySQL的ENCRYPT功能中.我的基本想法是我将从旧机器中转储我的虚拟用户表,然后在新机器中导入它.

只是为了仔细检查我试图再次存储一个字符串,ENCRYPT存储的数据是不同的.这是否意味着我不能像我想的那样导出/导入我的用户?

mysql unix linux hash crypt

3
推荐指数
1
解决办法
2612
查看次数

使用PHP crypt()时,MySQL中的密码应该用于什么字段类型

使用PHP crypt()方法我有一个PHP脚本来存储MySQL数据库中的用户加密密码.你能告诉我应该使用哪种字段来存储加密数据吗?

谢谢

php mysql crypt

3
推荐指数
1
解决办法
2万
查看次数

递归迭代每个字符组合

预期结果:

该程序采用哈希密码作为输入; 这被传递给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)

python string recursion crypt des

3
推荐指数
1
解决办法
742
查看次数

使用crypt.h中的crypt()

我正在为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彼此相等,即使它们的字符串不相同,也不是盐.

我在某处做了一个简单的指针错误吗?

谢谢,

c pointers crypt cs50

3
推荐指数
1
解决办法
5520
查看次数

标签 统计

crypt ×10

php ×6

mysql ×3

c ×2

hash ×2

string ×2

blowfish ×1

c# ×1

codeigniter ×1

cs50 ×1

des ×1

linux ×1

php-5.4 ×1

php-5.6 ×1

pointers ×1

python ×1

recursion ×1

ruby ×1

salt ×1

unix ×1