[英]MySQL hashed column password+script bash
我有點問題。
我創建了一個MySQL表,其中的密碼列已使用SHA1加密。
mysql> CREATE TABLE IF NOT EXISTS user_encrypted (
username varchar(50) COLLATE utf8_unicode_ci NOT NULL PRIMARY KEY DEFAULT 'username',
hashed_password varchar(50) COLLATE utf8_unicode_ci NOT NULL DEFAULT 'password',
user_mail varchar(64) COLLATE utf8_unicode_ci DEFAULT NULL DEFAULT 'your@email.com',
user_phone varchar(20) COLLATE utf8_unicode_ci DEFAULT NULL DEFAULT '+33 1 23 45 67 89',
user_online tinyint(1) NOT NULL DEFAULT '0',
user_enable tinyint(1) NOT NULL DEFAULT '1',
user_max_connection tinyint(1) NOT NULL DEFAULT '2',
user_start_date date NOT NULL DEFAULT '2015-05-01',
user_end_date date NOT NULL DEFAULT '0000-00-00',
KEY hashed_password (hashed_password)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
結果
Query OK, 0 rows affected (0.01 sec)
我要編寫一個腳本,該腳本調用MySQL表:
#!/bin/bash
. /etc/openvpn/script/config.sh
#New Encrypted_password
#username=$(mysql -h$HOST -P$PORT -u$USER -p$PASS $DB -sN -e "select username from user_encrypted where username = '$username' AND hashed_password = '$password' AND user_enable=1 AND user_max_connection=2 AND user_start_date != user_end_date AND TO_DAYS(now()) >= TO_DAYS(user_start_date) AND (TO_DAYS(now()) <= TO_DAYS(user_end_date) OR user_end_date='0000-00-00')")
##Check user
[ "$username" != '' ] && [ "$username" = "$username" ] && echo "user : $username" && echo 'authentication ok.' && exit 0 || echo 'authentication failed.'; exit 1
問題是,當我使用腳本並且OpenVPn要求我提供用戶名/密碼時,我使用Test和Test1234,但是系統拒絕密碼。 似乎“非加密”密碼無法轉換為加密密碼,無法檢查該表的密碼是否與我在客戶端OpenVPN中輸入的密碼相同。
我不知道該怎么辦,在我輸入的密碼的腳本bash中,“轉換”為加密的密碼,以便與數據庫進行檢查...
謝謝你
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.