-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathreset.js
executable file
·62 lines (59 loc) · 1.95 KB
/
reset.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const sha1 = require('sha1')
const rand = require('csprng')
const mongoose = require('mongoose')
mongoose.connect('mongodb://127.0.0.1:27017/shadowblog')
mongoose.connection.on('connected', function () {
console.log('connect success')
})
mongoose.connection.on('error', function (err) {
console.log('connect error:' + err)
})
let Schema = mongoose.Schema
const UserSchema = new Schema({
uid: String,
username: String,
password: String,
create_time: String,
logout_time: String,
login_time: String,
permission_code: String,
salt: String
}, {collection: 'user'})
const User = mongoose.model('User', UserSchema)
const incSchema = new Schema({
name: String,
id: Number
}, {collection: 'incs'})
const Incs = mongoose.model('Incs', incSchema)
const salt = rand(160, 36)
function currentTime () {
let currentDate = new Date()
let year = currentDate.getFullYear()
let month = currentDate.getMonth() + 1 < 10 ? '0' + (currentDate.getMonth() + 1) : (currentDate.getMonth() + 1)
let date = currentDate.getDate() < 10 ? '0' + currentDate.getDate() : currentDate.getDate()
let hours = currentDate.getHours() < 10 ? '0' + currentDate.getHours() : currentDate.getHours()
let minutes = currentDate.getMinutes() < 10 ? '0' + currentDate.getMinutes() : currentDate.getMinutes()
let seconds = currentDate.getSeconds() < 10 ? '0' + currentDate.getSeconds() : currentDate.getSeconds()
return year + '-' + month + '-' + date + ' ' + hours + ':' + minutes + ':' + seconds
}
let time = currentTime()
let psd = sha1('admin')
let newpsd = sha1(psd + salt)
let user1 = new User({
username: 'admin',
password: newpsd,
create_time: time,
login_time: time,
permission_code: 777,
salt: salt
})
let articleID = new Incs({
name: 'article',
id: 0
})
user1.save(function () {
articleID.save(function () {
console.log('ShadowBlog初始化成功,用户名:admin,密码:admin,权限:管理员,登录后请修改账户密码,请删除此文件!')
process.kill()
})
})