Greenplum身份验证方式-密码验证

基于密码的身份验证方式有两种:password 和 md5 ;

Password是明文密码 md5是加密后的密码

测试方法类似于基于IP的trust reject身份验证方式,但数据库连接参数 密码需要赋值。

首先新建两个用户  user2 ,user3

         创建用户及授权的命令

                   template1=#create user user2 with nosuperuser nocreatedb  password '123456a' ;

                   template1=# create user user3 with nosuperuser nocreatedb encrypted  password '123456a' ;

         然后管理员登陆数据库testdb,使得user2,user3可以访问表test1;

                   testdb=# GRANT all on table test1 to user2;

                   testdb=# GRANT all on table test1 to user3;

         测试password方式

                   服务端配置文件

                            host    testdb  user2   10.47.0.153/32  password

          host    testdb  user3   10.47.0.153/32  password

                   客户端代码

                            String url = "jdbc:postgresql://10.110.18.241/testdb";

                   Connection conn = DriverManager.getConnection(url, "user2", "123456a");

                   测试结果

                            User2,user3都连接数据库成功。

                  

         测试md5方式

                  服务端配置文件

                            host    testdb  user2   10.47.0.153/32  md5

          host    testdb  user3   10.47.0.153/32  md5

                   客户端代码

                            String url = "jdbc:postgresql://10.110.18.241/testdb";

              Connection conn = DriverManager.getConnection(url, "user2", "123456a");

                   测试结果

                            User2,user3都连接数据库成功。

分析:

     从测试情况看,服务端为数据库用户设置为password和md5,客户端密码为123456a都是可以的,那么password 和 md5 两种情况的区别在哪里呢?

     抓取了两种情况时的网络通信数据包,发现在运行时password网络传输的是明文,而md5方式网络传输的是md5编码后的密码。客户端程序是完全一样的。Md5避免了从网络抓包获取到明文的密码。

                  

       Password

              PostgreSQL

    Type: Password message

    Length: 12

    Password: 123456a

 

       Md5

             PostgreSQL

    Type: Password message

    Length: 40

    Password: md52a2922ec50be4efc34ba50cc1cc190e2

  如果网络通信使用了SSL,那么直接使用password也是安全的。

 从PostgreSQL8.4 中有说明 However, md5 cannot be used with the db_user_namespace Feature 。

原文地址:https://www.cnblogs.com/fangjx/p/6396109.html