@@ -57,42 +57,41 @@ if (settings.ep_hash_auth) {
57
57
// This function calls callback(hashType) if authenticated, or callback(null) if not.
58
58
const compareHashes = async ( password , hash , callback ) => {
59
59
const cryptoHash = crypto . createHash ( hash_typ ) . update ( password ) . digest ( hash_dig ) ;
60
+
60
61
if ( hash === cryptoHash ) { // Check whether this is a crypto hash first
61
62
return callback ( 'crypto' ) ;
62
- } else { // If not, check other hash types
63
- if ( hash [ 0 ] === '$' ) { // This is an argon2 or bcrypt hash
64
- if ( hash . slice ( 0 , 7 ) === '$argon2' ) { // This is argon2
65
- if ( argon2 ) {
66
- if ( await argon2 . verify ( hash , password ) ) {
67
- return callback ( 'argon2' ) ;
68
- } else {
69
- return callback ( null ) ;
70
- }
71
- } else {
72
- console . log ( 'Warning: Could not verify argon2 hash due to missing dependency' ) ;
73
- }
74
- } else { // This is bcrypt
75
- if ( bcrypt ) {
76
- if ( await bcrypt . compare ( password , hash ) ) {
77
- return callback ( 'bcrypt' ) ;
78
- } else {
79
- return callback ( null ) ;
80
- }
81
- } else {
82
- console . log ( 'Warning: Could not verify bcrypt hash due to missing dependency' ) ;
83
- }
84
- }
85
- } else { // This is a scrypt hash or a failed crypto hash
86
- if ( scrypt ) {
87
- if ( scrypt . verifyKdfSync ( Buffer . from ( hash , 'hex' ) , Buffer . from ( password ) ) ) {
88
- return callback ( 'scrypt' ) ;
63
+ // If not, check other hash types
64
+ } else if ( hash [ 0 ] === '$' ) {
65
+ // This is an argon2 or bcrypt hash
66
+ if ( hash . slice ( 0 , 7 ) === '$argon2' ) {
67
+ // This is argon2
68
+ if ( argon2 ) {
69
+ if ( await argon2 . verify ( hash , password ) ) {
70
+ return callback ( 'argon2' ) ;
89
71
} else {
90
72
return callback ( null ) ;
91
73
}
92
74
} else {
93
- console . log ( 'Warning: Could not verify scrypt hash due to missing dependency' ) ;
75
+ console . log ( 'Warning: Could not verify argon2 hash due to missing dependency' ) ;
76
+ }
77
+ } else if ( bcrypt ) {
78
+ if ( await bcrypt . compare ( password , hash ) ) {
79
+ return callback ( 'bcrypt' ) ;
80
+ } else {
81
+ return callback ( null ) ;
94
82
}
83
+ } else {
84
+ console . log ( 'Warning: Could not verify bcrypt hash due to missing dependency' ) ;
85
+ }
86
+ } else if ( scrypt ) {
87
+ // This is a scrypt hash or a failed crypto hash
88
+ if ( scrypt . verifyKdfSync ( Buffer . from ( hash , 'hex' ) , Buffer . from ( password ) ) ) {
89
+ return callback ( 'scrypt' ) ;
90
+ } else {
91
+ return callback ( null ) ;
95
92
}
93
+ } else {
94
+ console . log ( 'Warning: Could not verify scrypt hash due to missing dependency' ) ;
96
95
}
97
96
return callback ( null ) ;
98
97
} ;
0 commit comments