Skip to content

Commit

Permalink
feat: use md5 for password
Browse files Browse the repository at this point in the history
  • Loading branch information
tyanbiao committed Nov 26, 2020
1 parent 19f043b commit c051751
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@koa/router": "^10.0.0",
"blueimp-md5": "^2.18.0",
"ejs": "^3.1.5",
"koa": "^2.13.0",
"koa-bodyparser": "^4.3.0",
Expand Down
4 changes: 3 additions & 1 deletion src/middleware/router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const Router = require('@koa/router')
const md5 = require('blueimp-md5')

const {
application: applicationConf,
beancount: beancountConf,
Expand Down Expand Up @@ -27,7 +29,7 @@ router.post('/login', async (ctx, next) => {
const body = ctx.request.body
if (
body.username.trim() === applicationConf.username &&
body.password.trim() === applicationConf.password
body.password.trim() === md5(applicationConf.password)
) {
ctx.session.user = body.username
ctx.session.signin = true
Expand Down
2 changes: 2 additions & 0 deletions src/static/md5.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion src/view/login.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
</form>
</div>
<script src="/static/axios.min.js"></script>
<script src="/static/md5.min.js"></script>
<script>
const submitBtn = document.querySelector('#submit')
submitBtn.addEventListener('click', (e) => {
Expand All @@ -32,7 +33,7 @@
}
axios.post('/login', {
username,
password
password: md5(password),
})
.then(res => {
if (res.data && res.data.code === 0) {
Expand Down

0 comments on commit c051751

Please sign in to comment.