我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用crypt.mksalt()。
def update(cls, *args, **kwargs): """Update password hash on update""" if 'password' in kwargs.keys(): kwargs['phash'] = crypt.crypt(kwargs.pop('password'), crypt.mksalt()) return super().update(*args, **kwargs)
def create(cls, *args, **kwargs): """Update password hash on create""" if 'password' in kwargs.keys(): kwargs['phash'] = crypt.crypt(kwargs.pop('password'), crypt.mksalt()) return super().create(*args, **kwargs)
def save(self, *args, **kwargs): """Update password hash on save""" if getattr(self, 'password', None) is not None: self.phash = crypt.crypt(self.password, crypt.mksalt()) del self.password return super().save(*args, **kwargs)
def create(cls, *args, **kwargs): """ Update password hash on create """ if 'password' in kwargs.keys(): kwargs['phash'] = crypt.crypt(kwargs.pop('password'), crypt.mksalt()) return super().create(*args, **kwargs)
def update(cls, *args, **kwargs): """ Update password hash on update """ if 'password' in kwargs.keys(): kwargs['phash'] = crypt.crypt(kwargs.pop('password'), crypt.mksalt()) return super().update(*args, **kwargs)
def save(self, *args, **kwargs): """ Update password hash on save """ if getattr(self, 'password', None) is not None: self.phash = crypt.crypt(self.password, crypt.mksalt()) del self.password return super().save(*args, **kwargs)
def create_user(username, password, firstname, lastname, email, phone, email_to_file=None): if not validate_username(username): return [None, "Wrong user name format (are allowed a-Z|0-9|.|-|_)"] if not validate_email(email): return [None, "Wrong email format"] if Users.objects.filter(username=username): logging.warning("Cannot create account: username {} already exists".format(email)) return [None, "This username already exists"] if Users.objects.filter(email=email): logging.warning("Cannot create account: email {} already exists".format(email)) return [None, "This email already exists"] person = People.objects.create(firstname=firstname, lastname=lastname, phone=phone, is_laboratory=0) role = Roles.objects.get(name=DEFAULT_ROLE) salt = crypt.mksalt(method=crypt.METHOD_SHA256) newuser = Users(username=username, password=crypt.crypt(password, salt), salt=salt, email=email, person=person, role=role, is_active=0, is_password_reset=0, code=utils.random_string()) newuser.save() allow_access_to_demo(newuser) text = "Your account '{}' has been created. ".format(username) + \ "It will be validated by an admin shortly. You will receive an email at this " + \ "address when your account has been activated." html = text send_email(email, "New varapp account", text=text, html=html, tofile=email_to_file) send_email(settings.EMAIL_ADMIN, "Account for user {} awaits validation".format(username), text='', html='', tofile=email_to_file) return [newuser, '']
def __init__(self, username: str, password: str): Srp.__init__(self) self.username = username self.password = password self.salt = None self.a = gmpy2.mpz(int(binascii.hexlify(crypt.mksalt(crypt.METHOD_SHA512)[3:].encode()), 16)) self.A = pow(self.g, self.a, self.n) self.B = None
def __init__(self, username, password): Srp.__init__(self) self.username = username self.salt = SrpServer._create_salt() self.password = password self.verifier = self._get_verifier() salt = crypt.mksalt(crypt.METHOD_SHA256)[3:].encode() salt_b = binascii.hexlify(salt) self.b = gmpy2.mpz(int(salt_b, 16)) k = self._calculate_k() g_b = pow(self.g, self.b, self.n) self.B = (k * self.verifier + g_b) % self.n self.A = None
def _create_salt() -> gmpy2.mpz: salt = crypt.mksalt(crypt.METHOD_SHA512)[3:] salt_b = salt.encode() salt_hex = binascii.hexlify(salt_b) salt_int = int(salt_hex, 16) assert len(salt) == 16 return gmpy2.mpz(salt_int)