Class: Mysql::Authenticator::MysqlNativePassword
- Inherits:
-
Object
- Object
- Mysql::Authenticator::MysqlNativePassword
- Defined in:
- lib/mysql/authenticator/mysql_native_password.rb
Overview
mysql_native_password
Instance Method Summary collapse
- #authenticate(passwd, scramble) {|String| ... } ⇒ Mysql::Packet
-
#hash_password(passwd, scramble) ⇒ String
Hashed password.
-
#initialize(protocol) ⇒ MysqlNativePassword
constructor
A new instance of MysqlNativePassword.
- #name ⇒ String
Constructor Details
#initialize(protocol) ⇒ MysqlNativePassword
Returns a new instance of MysqlNativePassword.
8 9 10 |
# File 'lib/mysql/authenticator/mysql_native_password.rb', line 8 def initialize(protocol) @protocol = protocol end |
Instance Method Details
#authenticate(passwd, scramble) {|String| ... } ⇒ Mysql::Packet
21 22 23 24 |
# File 'lib/mysql/authenticator/mysql_native_password.rb', line 21 def authenticate(passwd, scramble) yield hash_password(passwd, scramble) @protocol.read end |
#hash_password(passwd, scramble) ⇒ String
Returns hashed password.
29 30 31 32 33 34 35 |
# File 'lib/mysql/authenticator/mysql_native_password.rb', line 29 def hash_password(passwd, scramble) return '' if passwd.nil? or passwd.empty? hash1 = Digest::SHA1.digest(passwd) hash2 = Digest::SHA1.digest(hash1) hash3 = Digest::SHA1.digest(scramble + hash2) hash1.unpack("C*").zip(hash3.unpack("C*")).map{|a, b| a ^ b}.pack("C*") end |
#name ⇒ String
13 14 15 |
# File 'lib/mysql/authenticator/mysql_native_password.rb', line 13 def name 'mysql_native_password' end |