forked from mirrors/amnezia-wg-easy
		
	fixup: bcrypt implementation
This commit is contained in:
		
							parent
							
								
									96420d6f51
								
							
						
					
					
						commit
						e3fd6cf8b4
					
				
					 1 changed files with 1 additions and 8 deletions
				
			
		| 
						 | 
					@ -82,16 +82,9 @@ module.exports = class Server {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (req.path.startsWith('/api/') && req.headers['authorization']) {
 | 
					        if (req.path.startsWith('/api/') && req.headers['authorization']) {
 | 
				
			||||||
          const authorizationHash = bcrypt.createHash('bcrypt')
 | 
					          if (bcrypt.compareSync(req.headers['authorization'], bcrypt.hashSync(PASSWORD, 10))) {
 | 
				
			||||||
            .update(req.headers['authorization'])
 | 
					 | 
				
			||||||
            .digest('hex');
 | 
					 | 
				
			||||||
          const passwordHash = bcrypt.createHash('bcrypt')
 | 
					 | 
				
			||||||
            .update(PASSWORD)
 | 
					 | 
				
			||||||
            .digest('hex');
 | 
					 | 
				
			||||||
          if (bcrypt.timingSafeEqual(Buffer.from(authorizationHash), Buffer.from(passwordHash))) {
 | 
					 | 
				
			||||||
            return next();
 | 
					            return next();
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
					 | 
				
			||||||
          return res.status(401).json({
 | 
					          return res.status(401).json({
 | 
				
			||||||
            error: 'Incorrect Password',
 | 
					            error: 'Incorrect Password',
 | 
				
			||||||
          });
 | 
					          });
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue