@nocobase/database 2.1.0-beta.42 → 2.1.0-beta.44
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -19,11 +19,13 @@ export interface PasswordFieldOptions extends BaseColumnFieldOptions {
|
|
|
19
19
|
*/
|
|
20
20
|
randomBytesSize?: number;
|
|
21
21
|
}
|
|
22
|
+
type PasswordValue = string | number;
|
|
22
23
|
export declare class PasswordField extends Field {
|
|
23
24
|
get dataType(): DataTypes.StringDataTypeConstructor;
|
|
24
|
-
verify(password:
|
|
25
|
-
hash(password:
|
|
25
|
+
verify(password: PasswordValue, hash: string): Promise<unknown>;
|
|
26
|
+
hash(password: PasswordValue): Promise<unknown>;
|
|
26
27
|
init(): void;
|
|
27
28
|
bind(): void;
|
|
28
29
|
unbind(): void;
|
|
29
30
|
}
|
|
31
|
+
export {};
|
|
@@ -48,23 +48,24 @@ const _PasswordField = class _PasswordField extends import_field.Field {
|
|
|
48
48
|
return import_sequelize.DataTypes.STRING;
|
|
49
49
|
}
|
|
50
50
|
async verify(password, hash) {
|
|
51
|
-
|
|
51
|
+
const passwordString = password === null || password === void 0 ? "" : String(password);
|
|
52
52
|
hash = hash || "";
|
|
53
53
|
const { length = 64, randomBytesSize = 8 } = this.options;
|
|
54
54
|
return new Promise((resolve, reject) => {
|
|
55
55
|
const salt = hash.substring(0, randomBytesSize * 2);
|
|
56
56
|
const key = hash.substring(randomBytesSize * 2);
|
|
57
|
-
import_crypto.default.scrypt(
|
|
57
|
+
import_crypto.default.scrypt(passwordString, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
|
|
58
58
|
if (err) reject(err);
|
|
59
59
|
resolve(key == derivedKey.toString("hex"));
|
|
60
60
|
});
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
async hash(password) {
|
|
64
|
+
const passwordString = String(password);
|
|
64
65
|
const { length = 64, randomBytesSize = 8 } = this.options;
|
|
65
66
|
return new Promise((resolve, reject) => {
|
|
66
67
|
const salt = import_crypto.default.randomBytes(randomBytesSize).toString("hex");
|
|
67
|
-
import_crypto.default.scrypt(
|
|
68
|
+
import_crypto.default.scrypt(passwordString, salt, length / 2 - randomBytesSize, (err, derivedKey) => {
|
|
68
69
|
if (err) reject(err);
|
|
69
70
|
resolve(salt + derivedKey.toString("hex"));
|
|
70
71
|
});
|
|
@@ -72,18 +73,20 @@ const _PasswordField = class _PasswordField extends import_field.Field {
|
|
|
72
73
|
}
|
|
73
74
|
init() {
|
|
74
75
|
const { name } = this.options;
|
|
76
|
+
const fieldName = name;
|
|
75
77
|
this.listener = async (instances) => {
|
|
76
78
|
instances = Array.isArray(instances) ? instances : [instances];
|
|
77
79
|
for (const instance of instances) {
|
|
78
|
-
if (!instance.changed(
|
|
80
|
+
if (!instance.changed(fieldName)) {
|
|
79
81
|
continue;
|
|
80
82
|
}
|
|
81
|
-
const value = instance.get(
|
|
82
|
-
if (value) {
|
|
83
|
-
const
|
|
84
|
-
|
|
83
|
+
const value = instance.get(fieldName);
|
|
84
|
+
if (value !== null && value !== void 0 && value !== "") {
|
|
85
|
+
const password = typeof value === "number" ? value : String(value);
|
|
86
|
+
const hash = await this.hash(password);
|
|
87
|
+
instance.set(fieldName, hash);
|
|
85
88
|
} else {
|
|
86
|
-
instance.set(
|
|
89
|
+
instance.set(fieldName, instance.previous(fieldName));
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nocobase/database",
|
|
3
|
-
"version": "2.1.0-beta.
|
|
3
|
+
"version": "2.1.0-beta.44",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
7
|
"license": "Apache-2.0",
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@nocobase/logger": "2.1.0-beta.
|
|
10
|
-
"@nocobase/utils": "2.1.0-beta.
|
|
9
|
+
"@nocobase/logger": "2.1.0-beta.44",
|
|
10
|
+
"@nocobase/utils": "2.1.0-beta.44",
|
|
11
11
|
"async-mutex": "^0.3.2",
|
|
12
12
|
"chalk": "^4.1.1",
|
|
13
13
|
"cron-parser": "4.4.0",
|
|
@@ -38,5 +38,5 @@
|
|
|
38
38
|
"url": "git+https://github.com/nocobase/nocobase.git",
|
|
39
39
|
"directory": "packages/database"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "540d4897b1696cc24c0754521b0b766978b4933c"
|
|
42
42
|
}
|