You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
	
	
		
		
			
	
	
		
			
				
					
						
							|  |  |  | from passlib.context import CryptContext | 
					
						
							|  |  |  | import hashlib | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | pwd_context = CryptContext(schemes=['bcrypt'], deprecated='auto') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class PwdUtil: | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def md5_hash(cls, password): | 
					
						
							|  |  |  |         # 创建一个md5 hash对象 | 
					
						
							|  |  |  |         hash_object = hashlib.md5(password.encode()) | 
					
						
							|  |  |  |         # 获取16进制的hash值 | 
					
						
							|  |  |  |         hex_dig = hash_object.hexdigest() | 
					
						
							|  |  |  |         return hex_dig | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     密码工具类 | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def verify_password(cls, plain_password, hashed_password): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         工具方法:校验当前输入的密码与数据库存储的密码是否一致 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         :param plain_password: 当前输入的密码 | 
					
						
							|  |  |  |         :param hashed_password: 数据库存储的密码 | 
					
						
							|  |  |  |         :return: 校验结果 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         return pwd_context.verify(plain_password, hashed_password) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     @classmethod | 
					
						
							|  |  |  |     def get_password_hash(cls, input_password): | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         工具方法:对当前输入的密码进行加密 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         :param input_password: 输入的密码 | 
					
						
							|  |  |  |         :return: 加密成功的密码 | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         return pwd_context.hash(input_password) |