Commit 2fa7392 1 parent 1f7cec8 commit 2fa7392 Copy full SHA for 2fa7392
File tree 6 files changed +24
-21
lines changed
6 files changed +24
-21
lines changed Original file line number Diff line number Diff line change @@ -3,4 +3,5 @@ node_modules/
3
3
dist /
4
4
npm-debug.log
5
5
img /
6
- .vscode /
6
+ .vscode /
7
+ .idea /
Original file line number Diff line number Diff line change 6
6
"private" : true ,
7
7
"scripts" : {
8
8
"dev" : " node build/dev-server.js" ,
9
- "build" : " node build/build.js"
9
+ "build" : " node build/build.js" ,
10
+ "server" : " node app.js"
10
11
},
11
12
"dependencies" : {
12
13
"axios" : " ^0.15.3" ,
14
+ "bcryptjs" : " ^2.4.0" ,
13
15
"element-ui" : " ^1.1.2" ,
14
16
"koa" : " ^1.2.4" ,
15
17
"koa-bodyparser" : " ^2.3.0" ,
19
21
"koa-logger" : " ^1.3.0" ,
20
22
"koa-router" : " 5.4" ,
21
23
"koa-static" : " ^2.0.0" ,
22
- "md5" : " ^2.2.1" ,
23
24
"mysql" : " ^2.12.0" ,
24
25
"sequelize" : " ^3.29.0" ,
25
26
"stylus" : " ^0.54.5" ,
Original file line number Diff line number Diff line change 1
1
const user = require ( '../models/user.js' ) ;
2
2
const jwt = require ( 'koa-jwt' ) ;
3
+ const bcrypt = require ( 'bcryptjs' ) ;
3
4
4
5
const getUserInfo = function * ( ) {
5
6
const id = this . params . id ; // 获取url里传过来的参数里的id
@@ -13,7 +14,7 @@ const postUserAuth = function* (){
13
14
const userInfo = yield user . getUserByName ( data . name ) ;
14
15
console . log ( this . request )
15
16
if ( userInfo != null ) { // 如果查无此用户会返回null
16
- if ( userInfo . password != data . password ) {
17
+ if ( ! bcrypt . compareSync ( data . password , userInfo . password ) ) {
17
18
this . body = {
18
19
success : false , // success标志位是方便前端判断返回是正确与否
19
20
info : '密码错误!'
@@ -43,4 +44,4 @@ module.exports = {
43
44
router . get ( '/user/:id' , getUserInfo ) ; // 定义url的参数是id
44
45
router . post ( '/user' , postUserAuth ) ;
45
46
}
46
- }
47
+ }
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ module.exports = function(sequelize, DataTypes) {
13
13
allowNull : false
14
14
} ,
15
15
password : {
16
- type : DataTypes . CHAR ( 32 ) ,
16
+ type : DataTypes . CHAR ( 128 ) ,
17
17
allowNull : false
18
18
}
19
19
} , {
Original file line number Diff line number Diff line change @@ -20,15 +20,17 @@ USE `todolist`;
20
20
CREATE TABLE IF NOT EXISTS ` user` (
21
21
` id` int (11 ) NOT NULL AUTO_INCREMENT,
22
22
` user_name` char (50 ) NOT NULL ,
23
- ` password` char (32 ) NOT NULL ,
23
+ ` password` char (128 ) NOT NULL ,
24
24
PRIMARY KEY (` id` )
25
25
) ENGINE= InnoDB AUTO_INCREMENT= 2 DEFAULT CHARSET= utf8;
26
26
27
27
-- 正在导出表 todolist.user 的数据:~0 rows (大约)
28
28
DELETE FROM ` user` ;
29
29
/* !40000 ALTER TABLE `user` DISABLE KEYS */ ;
30
- INSERT INTO ` user` (` id` , ` user_name` , ` password` ) VALUES
31
- (1 , ' molunerfinn' , ' 202cb962ac59075b964b07152d234b70' );
30
+ INSERT INTO ` user` (` user_name` , ` password` ) VALUES
31
+ (' molunerfinn' , ' $2a$10$x3f0Y2SNAmyAfqhKVAV.7uE7RHs3FDGuSYw.LlZhOFoyK7cjfZ.Q6' );
32
+ INSERT INTO ` user` (` user_name` , ` password` ) VALUES
33
+ (' admin' , ' $2a$10$x3f0Y2SNAmyAfqhKVAV.7uE7RHs3FDGuSYw.LlZhOFoyK7cjfZ.Q6' );
32
34
/* !40000 ALTER TABLE `user` ENABLE KEYS */ ;
33
35
34
36
/* !40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */ ;
Original file line number Diff line number Diff line change 2
2
<el-row class =" content" >
3
3
<el-col :xs =" 24" :sm =" {span: 6,offset: 9}" >
4
4
<span class =" title" >
5
- 欢迎登录
5
+ 欢迎登录
6
6
</span >
7
7
<el-row >
8
- <el-input
9
- v-model =" account"
8
+ <el-input
9
+ v-model =" account"
10
10
placeholder =" 账号"
11
11
type =" text" >
12
12
</el-input >
13
- <el-input
14
- v-model =" password"
13
+ <el-input
14
+ v-model =" password"
15
15
placeholder =" 密码"
16
16
type =" password"
17
17
@keyup.enter.native =" loginToDo" >
23
23
</template >
24
24
25
25
<script >
26
- import md5 from ' md5'
27
-
28
26
export default {
29
27
data () {
30
28
return {
@@ -36,8 +34,8 @@ export default {
36
34
loginToDo () {
37
35
let obj = {
38
36
name: this .account ,
39
- password: md5 ( this .password )
40
- }
37
+ password: this .password
38
+ }
41
39
this .$http .post (' /auth/user' , obj) // 将信息发送给后端
42
40
.then ((res ) => {
43
41
console .log (res);
@@ -46,7 +44,7 @@ export default {
46
44
this .$message ({ // 登录成功,显示提示语
47
45
type: ' success' ,
48
46
message: ' 登录成功!'
49
- });
47
+ });
50
48
this .$router .push (' /todolist' ) // 进入todolist页面,登录成功
51
49
}else {
52
50
this .$message .error (res .data .info ); // 登录失败,显示提示语
@@ -70,5 +68,5 @@ export default {
70
68
margin 12px 0
71
69
.el-button
72
70
width 100%
73
- margin-top 12px
74
- </style >
71
+ margin-top 12px
72
+ </style >
You can’t perform that action at this time.
0 commit comments