我们从Python开源项目中,提取了以下31个代码示例,用于说明如何使用django.contrib.auth.password_validation.validate_password()。
def clean_password2(self): password1 = self.cleaned_data.get('password1') password2 = self.cleaned_data.get('password2') # ?? ?? ???? ??? # ???? ??? & ?????? ????? ?? # https://docs.djangoproject.com/en/1.10/topics/auth/passwords/ if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) password_validation.validate_password( self.cleaned_data['password2'], self.instance ) return password2
def is_invalid_password(password, repeat_password): """ check passwords strength and equality :param password: :param repeat_password: :return error message or None: """ error_messages = { 'not_match': 'Password and Repeat Password fields must match.', } if not password or (not password and not repeat_password): return error_message = '' try: password_validation.validate_password(password=password, ) except forms.ValidationError as e: error_message = list(e.messages) if error_message: return forms.ValidationError(error_message) if password != repeat_password: return forms.ValidationError(error_messages['not_match'])
def validate_new_password(self, password): """ Validate the user's new password. We validate the password by running it through Django's password validation system. Args: password (str): The password to validate. Returns: str: The validated password. Raises: ValidationError: If the password is not valid. """ password_validation.validate_password(password) return password
def validate_password(self, password): """ Validate the provided password. This runs the password through Django's password validation system. Args: password (str): The password to validate. Returns: str: The validated password. Raises: ValidationError: If the provided password does not pass Django's password validation checks. """ password_validation.validate_password(password, self.instance) return password
def clean_password2(self): # Check that the two password entries match password = self.cleaned_data.get("password") password2 = self.cleaned_data.get("password2") if password and password2 and password != password2: raise forms.ValidationError("Passwords don't match") validate_password(password) return password2
def clean_new_password2(self): password1 = self.cleaned_data.get('new_password1') password2 = self.cleaned_data.get('new_password2') if password1 and password2: if password1 != password2: raise forms.ValidationError("The two password fields didn't match.") password_validation.validate_password(password2) return password2
def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) if password_validation: self.instance.email = self.cleaned_data.get('email') password_validation.validate_password(self.cleaned_data.get('password2'), self.instance) return password2
def clean_password(self): password = self.cleaned_data.get('password') self.instance.username = self.cleaned_data.get('username') password_validation.validate_password(password, self.instance) return password
def validate_password(self, password, instance): pass
def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) self.instance.username = self.cleaned_data.get('username') password_validation.validate_password(self.cleaned_data.get('password2'), self.instance) return password2
def clean_password(self): password = self.cleaned_data['password'] password_validation.validate_password(password, self.instance) return password
def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) self.instance.username = self.cleaned_data.get('username') self.instance.email = self.cleaned_data.get('email') self.instance.first_name = self.cleaned_data.get('firstname') self.instance.last_name = self.cleaned_data.get('lastname') password_validation.validate_password(self.cleaned_data.get('password2'), self.instance) return password2
def validate_password(password, user=None, password_validators=None): pass
def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError( self.error_messages['password_mismatch'], code='password_mismatch', ) self.instance.email = self.cleaned_data.get('email') password_validation.validate_password(self.cleaned_data.get('password2'), self.instance) return password2
def validate_password(self, value): validate_password(value) return value
def validate(self, data): new, new2 = data['new1'], data['new2'] if new and new2 and new != new2: raise serializers.ValidationError( 'New passwords mismatched!') validate_password(new) return data
def validate_new_password(self, value): validate_password(value) return value
def validate(self, data): if data['password1'] != data['password2']: raise serializers.ValidationError("The two password fields didn't match.") errors = dict() try: password_validation.validate_password(password=data['password1'], user=CustomUser) except exceptions.ValidationError as e: errors['password'] = list(e.messages) if errors: raise serializers.ValidationError(errors) return data
def validate_password(password): """ Validate password """ validate_password(password) return password
def validate(self, attrs): try: validators.validate_password(attrs['password']) except exceptions.ValidationError as e: raise serializers.ValidationError({'password': ['Senha inválida']}) return attrs
def validate(self, attrs): if attrs['new_password'] != attrs['new_password2']: raise serializers.ValidationError({'password': ['A confirmação de senha e a senha são diferentes.']}) try: validators.validate_password(attrs['new_password']) except exceptions.ValidationError as e: raise serializers.ValidationError({'password': ['Senha inválida']}) return attrs