Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby 比较bcrypt散列_Ruby - Fatal编程技术网

Ruby 比较bcrypt散列

Ruby 比较bcrypt散列,ruby,Ruby,由于某种原因,身份验证失败。但是,如果我将哈希打印到stdout,它是相同的。有人知道怎么了吗 if File.exists?(passwdFile) File.open("#{passwdFile}",'r').each do |account| @account = account.split(':') usernameCheck = @account[0] # Stored username passwordCheck = @account[

由于某种原因,身份验证失败。但是,如果我将哈希打印到stdout,它是相同的。有人知道怎么了吗

if File.exists?(passwdFile)  
    File.open("#{passwdFile}",'r').each do |account|
      @account = account.split(':')
      usernameCheck = @account[0] # Stored username
      passwordCheck = @account[1] # Stored hashed password
      if username == usernameCheck
        # Create hash for given password to compare againts our stored one.
        password_hash = BCrypt::Engine.hash_secret(password, password_salt)
        puts "#{password_hash}"
        puts "#{passwordCheck}"
        if passwordCheck == password_hash
          @log.info 'Successfull authentication'
          return true
密码文件如下所示:

bob:$2a$10$1xNjCZxjv0R06qUm1lQEEeZ1uKuZ9ELQIkT2h5/TxCI9eHDurr.dW

File#返回的每行
都在行尾包含新行,因此
passwordCheck
变量有一个尾随的新行,但bcrypt生成的哈希没有

您可以使用
chomp