Home > Database > Mysql Tutorial > body text

mysql身份验证_MySQL

WBOY
Release: 2016-06-01 13:29:41
Original
1432 people have browsed it

bitsCN.com

mysql身份验证

 

MySQL的身份认证协议是一种CHAP协议,即,挑战应答。

 

S->C : public_seed

 

C->S: username, reply

 

S->C: Ok or error

 

对于4.1及以后版本,public_seed是随机生的20个可打印的ASCII字符

 

然后客户端这么计算reply:

passphrase=sha1("password")

storedhash=sha1(passphrase)

reply=xor(passphrase, sha1(public_seed,storedhash)

 

其中storedhash即是服务器存在数据库中的hash过的密码。

 

然后服务器在收到reply后这么对比:

 

先从数据库中根据username查到storedhash。

 

然后计算passphrase。原理是xor是可逆的。

passphrase=xor(reply, sha1(public_seed,storedhash))

 

然后对passphrase做sha1,和storedhash做二进制比较

sha1(passphrase)==storedhash

 

 

首先,我们知道,用户密码是保存在mysql.user这个表的password列,并且是以hash值的形式加密保存的。

 

 

整个验证过程如下:当客户端请求连接时,

 

 

1.服务器端会随机生成一个random string发送给客户端;

 

 

2.客户端收到random string后,进行hash加密

 

     第一步,将密码hash,得到hash值hash_stage1;  eg.hash_stage1=sha1("password"); 

 

     第二步,二次hash,得到hash_stage2;  eg. hash_stage2=sha1(hash_stage1);

 

     第三步,将密码二次hash得到的值与random string进行hash,得到hash_stage3; eg. hash_stage3=sha1("random string",hash_stage2);

 

     第四步,异或处理准备发送给服务器端,得到reply=xor(hash_stage1,hash_stage3);

 

     最后,将reply的值发送给服务器端。

 

 

3.服务器端收到reply后同样进行hash运算

 

    第一步,将保存的hash形式的密码hashpassword与random string进行hash,得到server_hash_stage1=sha1("random string","hashpassword");

 

    第二步,将客户端发送的reply与刚才得到的hash值进行异或运算,得到xor_value; eg. xor_value=xor(reply,server_hash_stage1);

 

    第三步,将得到的异或值进行hash,得到server_hash_stage2; eg. server_hash_stage2=sha1(server_hash_stage1);

 

    第四步,验证,将最后得到的hash值server_hash_stage2与保存的密码hashpassword进行比较。eg.   server_hash_stage2==hashpassword,相等则验证通过。

 

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!