登陸 資料庫查詢 以及redis校驗驗證碼

2022-07-22 11:42:08 字數 1401 閱讀 4168

```

//用於生成驗證ma

const svgcaptcha = require("

svg-captcha")

//mysql 用於在資料庫中查詢前端輸入的使用者名稱和密碼

const mysql = require('

mysql');

const connection =mysql.createconnection();

connection.connect();

//redis資料庫用於儲存隨機生成的驗證碼

//便於及時更新

const client =redis.createclient();

//redis 如果沒有啟動redis,會報錯

//redis 啟動命令 redis-server

//新建terminal 輸入redis-cli

client.on(

"error

", function (err) )

//生成token 方便redis儲存和替換

function getid(length)

//驗證碼

/cap

", (req, res) =>

//text:隨機生成的四位驗證碼

//data:傳遞給前端的驗證碼的

let text =cap.text;

res.type(

"svg");

//生成乙個id redis儲存 並傳遞給前端

let captchaid = getid(10

) client.

set(captchaid, text)

res.send()

return

})

//前端引用 //

this.getcaptcha()}>

//登陸

/getlogin

", async (req, res) => =req.body;

let rediscaptcha = await

new promise((resolve) =>)

})if (verification ===rediscaptcha)

else

)

return

}

//資料庫中查詢資料

connection.query(`select * from table where username='

$' &&passwrd='$'

`, function (error, results, fields) )

} else

)

return

} });

})```

便簽8 資料庫登陸

1.資料庫知識點 php mysql資料庫程式設計的步驟 第一步 登入到mysql伺服器 第二步 選擇當前資料庫 第三步 設定請求資料的字符集 第四步 執行sql語句 link mysql connect db host,db user,db pwd echo php連線資料庫失敗!mysql er...

資料庫登陸1045錯誤

報錯內容 error 1045 28000 access denied for user root localhost using password yes 解決方法 1 停止mysql服務 有兩種方法 1.控制台輸入 net stop mysql 注意 這種情況需要在c盤中,用管理員的方式啟動cm...

mysql資料庫安全模式登陸

當使用mysql資料庫提示密碼錯誤或無許可權等問題時,可以通過mysql的安全模式啟動資料庫,使所有使用者可以完全訪問所有的表,可以對使用者重設密碼,也可以進行許可權修改。1 首先關閉mysql資料庫,並結束所有mysqld程序。service mysqld stop killall 9 mysql...