Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def validate_password(username, password):
try:
validators.validate_password(username, password)
except ValueError as ex:
raise ValidationError(str(ex))
validator=lambda pwd: validate_password(
account['user_name'], pwd),
)
def _get_password(request: HttpRequest, addr_name: Optional[str]) -> Any:
# If addr_name is None, then this is a wildcard address, and those can't
# have passwords.
if addr_name is None:
return REMOVE_PASSWORD
password = request.POST.get('password')
if password is not None:
password = password.strip()
if not password:
return REMOVE_PASSWORD
try:
validate_password(addr_name, password, strength_check=True)
except ValueError as ex:
_error(request, ex.args[0])
else:
return crypt_password(password)
def change_password_with_keytab(username, password, keytab, principal, comment=None):
"""Change a user's Kerberos password using a keytab, subject to username
and password validation.
:param comment: comment to include in notification email
"""
validators.validate_username(username, check_exists=True)
validators.validate_password(username, password)
# try changing using kadmin pexpect
cmd = '{kadmin_path} -K {keytab} -p {principal} cpw {username}'.format(
kadmin_path=shlex.quote(KADMIN_PATH),
keytab=shlex.quote(keytab),
principal=shlex.quote(principal),
username=shlex.quote(username))
child = pexpect.spawn(cmd, timeout=10)
child.expect("{}@OCF.BERKELEY.EDU's Password:".format(username))
child.sendline(password)
child.expect("Verify password - {}@OCF.BERKELEY.EDU's Password:"
.format(username))
child.sendline(password)
def change_password_with_staffer(username, password, principal,
admin_password, comment=None):
"""Change a user's Kerberos password using kadmin and a password, subject
to username and password validation.
:param comment: comment to include in notification email
"""
validators.validate_username(username)
validators.validate_password(username, password)
# try changing using kadmin pexpect
cmd = '{kadmin_path} -p {principal} cpw {username}'.format(
kadmin_path=shlex.quote(KADMIN_PATH),
principal=shlex.quote(principal),
username=shlex.quote(username))
child = pexpect.spawn(cmd, timeout=10)
child.expect("{}@OCF.BERKELEY.EDU's Password:".format(username))
child.sendline(password)
child.expect("Verify password - {}@OCF.BERKELEY.EDU's Password:"
.format(username))
child.sendline(password)
# now give admin principal password