1
1
import * as cp from "child_process"
2
2
import * as crypto from "crypto"
3
- import * as bcrypt from "bcrypt "
3
+ import * as argon2 from "argon2 "
4
4
import envPaths from "env-paths"
5
5
import { promises as fs } from "fs"
6
6
import * as net from "net"
@@ -9,6 +9,7 @@ import * as path from "path"
9
9
import * as util from "util"
10
10
import xdgBasedir from "xdg-basedir"
11
11
import safeCompare from "safe-compare"
12
+ import { logger } from "@coder/logger"
12
13
13
14
export interface Paths {
14
15
data : string
@@ -120,15 +121,25 @@ export const generatePassword = async (length = 24): Promise<string> => {
120
121
/**
121
122
* Used to hash the password.
122
123
*/
123
- export const hash = ( password : string ) : string => {
124
- return bcrypt . hashSync ( password , 10 )
124
+ export const hash = async ( password : string ) => {
125
+ try {
126
+ return await argon2 . hash ( password )
127
+ } catch ( error ) {
128
+ logger . error ( error )
129
+ return ""
130
+ }
125
131
}
126
132
127
133
/**
128
134
* Used to verify if the password matches the hash
129
135
*/
130
- export const isHashMatch = ( password : string , hash : string ) => {
131
- return bcrypt . compareSync ( password , hash )
136
+ export const isHashMatch = async ( password : string , hash : string ) => {
137
+ try {
138
+ return await argon2 . verify ( hash , password )
139
+ } catch ( error ) {
140
+ logger . error ( error )
141
+ return false
142
+ }
132
143
}
133
144
134
145
/**
0 commit comments