refactor(striker-ui-api): hoist encrypt password

main
Tsu-ba-me 2 years ago
parent a16d5160d4
commit b080d319af
  1. 10
      striker-ui-api/src/lib/accessModule.ts
  2. 24
      striker-ui-api/src/middlewares/passport.ts
  3. 15
      striker-ui-api/src/types/EncryptFunction.d.ts

@ -246,6 +246,15 @@ const refreshTimestamp = () => {
return result; return result;
}; };
const encrypt: EncryptFunction = async (params) => {
const [result]: [Encrypted] = await subroutine('encrypt_password', {
params: [params],
pre: ['Account'],
});
return result;
};
const getData = async <T>(...keys: string[]) => { const getData = async <T>(...keys: string[]) => {
const chain = `data->${keys.join('->')}`; const chain = `data->${keys.join('->')}`;
@ -379,6 +388,7 @@ export {
insertOrUpdateVariable as variable, insertOrUpdateVariable as variable,
anvilSyncShared, anvilSyncShared,
refreshTimestamp as timestamp, refreshTimestamp as timestamp,
encrypt,
getData, getData,
getAnvilData, getAnvilData,
getFenceSpec, getFenceSpec,

@ -3,7 +3,7 @@ import { Strategy as LocalStrategy } from 'passport-local';
import { DELETED } from '../lib/consts'; import { DELETED } from '../lib/consts';
import { query, sub } from '../lib/accessModule'; import { encrypt, query } from '../lib/accessModule';
import { sanitize } from '../lib/sanitize'; import { sanitize } from '../lib/sanitize';
import { stdout } from '../lib/shell'; import { stdout } from '../lib/shell';
@ -47,24 +47,14 @@ passport.use(
0: [userUuid, , userPasswordHash, userSalt, userAlgorithm, userHashCount], 0: [userUuid, , userPasswordHash, userSalt, userAlgorithm, userHashCount],
} = rows; } = rows;
let encryptResult: { let encryptResult: Encrypted;
user_password_hash: string;
user_salt: string;
user_hash_count: number;
user_algorithm: string;
};
try { try {
[encryptResult] = await sub('encrypt_password', { encryptResult = await encrypt({
params: [ algorithm: userAlgorithm,
{ hash_count: userHashCount,
algorithm: userAlgorithm, password,
hash_count: userHashCount, salt: userSalt,
password,
salt: userSalt,
},
],
pre: ['Account'],
}); });
} catch (subError) { } catch (subError) {
return done(subError); return done(subError);

@ -0,0 +1,15 @@
type EncryptParams = SubroutineCommonParams & {
algorithm?: string;
hash_count?: string;
password: string;
salt?: string;
};
type Encrypted = {
user_algorithm: string;
user_hash_count: number;
user_password_hash: string;
user_salt: string;
};
type EncryptFunction = (params: EncryptParams) => Promise<Encrypted>;
Loading…
Cancel
Save