使用ALTER USER命令修改用戶的密碼、密碼過時,鎖定,解鎖
(1)修改用戶的口令,將用戶的口令修改成新的密碼數據庫
highgo=#create user test with password ‘test’;spa
CREATEROLEmd5
highgo=#select usename,passwd from pg_shadow;it
usename | passwd io
———+————————————-class
highgo | md5614aeb636ab143b790547ce463ec1741test
a | md5039af99d1e9a4b194e0eb800a6f8d018登錄
b | md583aeaa4e529325e234e9c5c2e01e6c08select
test | md505a671c66aefea124cc08b76ea6d30bb密碼
(4rows)
highgo=#ALTER USER test with password ‘testnew’;
ALTERROLE
highgo=#select usename,passwd from pg_shadow;
usename | passwd
———+————————————-
highgo | md5614aeb636ab143b790547ce463ec1741
a | md5039af99d1e9a4b194e0eb800a6f8d018
b | md583aeaa4e529325e234e9c5c2e01e6c08
test | md57c56448e70f764f1ca97ceae33823c9b
(4rows)
(2)設置用戶口令過時,經過設置用戶過時,這樣該用戶在下次登陸的時候就必需要修改密碼。
highgo=# select usename,valuntil from pg_shadow;
usename | valuntil
———+———-
highgo |
a |
b |
test |
(4rows)
highgo=#alter user test with valid until ‘2017-4-4 12:48:00’;
ALTERROLE
highgo=#select usename,valuntil from pg_shadow;
usename | valuntil
———+————————
highgo |
a |
b |
test | 2017-04-04 12:48:00+08
(4rows)
此時遠程使用test鏈接數據庫將失敗。
(3)鎖定用戶,將用戶鎖定以後,被鎖定的用戶是不可以再次登陸到系統中。
highgo=#ALTER USER test nologin;
ALTERROLE
highgo=#\c highgo test
致命錯誤: 不容許角色」test」進行登陸
致命錯誤: 不容許角色」test」進行登陸
Previousconnection kept
highgo=#
(4)解鎖用戶,解鎖用戶的鎖定狀態。
highgo=#ALTER USER test login;
ALTERROLE
highgo=#\c highgo test
Youare now connected to database 「highgo」 as user 「test」.
highgo=>