Esempio n. 1
0
def log_in_user(parsed_args: Namespace) -> None:
    if parsed_args.username is None:
        username = input("Username: "******"Password for user '{}': ".format(username)

    # In order to not send clear-text passwords, we hash the password.
    password = api.salt_and_hash(getpass.getpass(message))

    auth_inst = api.Authentication.instance()

    auth.do_login(parsed_args.master, auth_inst, username=username, password=password)
    auth_inst.token_store.set_active(username, True)
Esempio n. 2
0
def change_password(parsed_args: Namespace) -> None:
    auth_inst = api.Authentication.instance()

    if parsed_args.target_user:
        username = parsed_args.target_user
    elif parsed_args.user:
        username = parsed_args.user
    else:
        username = auth_inst.get_session_user()

    if not username:
        # The default user should have been set by now by autologin.
        print(
            colored("Please log in as an admin or user to change passwords",
                    "red"))
        return

    # If the target user's password isn't being changed by another user, reauthenticate after
    # password change so that the user doesn't have to do so manually.
    reauthenticate = parsed_args.target_user is None

    password = getpass.getpass("New password for user '{}': ".format(username))
    check_password = getpass.getpass("Confirm password: "******"Passwords do not match", "red"))
        return

    # Hash the password to avoid sending it in cleartext.
    password = api.salt_and_hash(password)

    update_user(username, parsed_args.master, password=password)

    if reauthenticate:
        set_active = auth_inst.is_user_active(username)
        auth_inst = api.Authentication.instance()

        auth.do_login(parsed_args.master, auth_inst, username, password)
        auth_inst.token_store.set_active(username, set_active)