En-/decryption fixed
This commit is contained in:
@@ -1,25 +1,18 @@
|
||||
import { sequelize } from '../../utils/sequelize.js';
|
||||
import { DataTypes } from 'sequelize';
|
||||
import bcrypt from 'bcrypt';
|
||||
import { encrypt, generateIv } from '../../utils/encryption.js';
|
||||
import { encrypt, decrypt } from '../../utils/encryption.js';
|
||||
import crypto from 'crypto';
|
||||
|
||||
const User = sequelize.define('user', {
|
||||
email: {
|
||||
type: DataTypes.STRING,
|
||||
type: DataTypes.BLOB, // Verwende BLOB, um die E-Mail als bytea zu speichern
|
||||
allowNull: false,
|
||||
unique: true,
|
||||
set(value) {
|
||||
if (value) {
|
||||
const iv = generateIv();
|
||||
this.setDataValue('iv', iv.toString('hex'));
|
||||
this.setDataValue('email', encrypt(value, iv));
|
||||
this.setDataValue('email', Buffer.from(encrypt(value), 'hex'));
|
||||
}
|
||||
}
|
||||
},
|
||||
iv: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false
|
||||
},
|
||||
},
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
@@ -46,6 +39,14 @@ const User = sequelize.define('user', {
|
||||
hashedId: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
},
|
||||
searchable: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: true
|
||||
},
|
||||
authCode: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true
|
||||
}
|
||||
}, {
|
||||
tableName: 'user',
|
||||
@@ -57,6 +58,11 @@ const User = sequelize.define('user', {
|
||||
user.hashedId = hashedId;
|
||||
await user.save();
|
||||
}
|
||||
},
|
||||
getterMethods: {
|
||||
email() {
|
||||
return decrypt(this.getDataValue('email').toString('hex'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user