Helix Core is now P4. Product user interfaces will be updated soon. Learn more >>

P4 API for Go Documentation | 2025.2

# Change a user's password

The following is an example of how to change your password using P4 API for Go.

Copy

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    // Set the user for whom the password will be changed
    p4api.SetUser("test_user")

    // Step 1: Set a new password
    fmt.Println("Setting a new password...")
    msg, err := p4api.RunPassword("", "new_password")
    if err != nil {
        fmt.Println("Failed to set password:", err)
        return
    }
    fmt.Println("Password set successfully:", msg.String())

    // Step 2: Verify the password by logging in
    fmt.Println("Logging in with the new password...")
    p4api.SetPassword("new_password")
    loginResult, err := p4api.RunLogin()
    if err != nil {
        fmt.Println("Failed to log in:", err)
        return
    }
    fmt.Println("Login successful:", loginResult)

    // Step 3: Change the password again
    fmt.Println("Changing the password...")
    msg, err = p4api.RunPassword("new_password", "updated_password")
    if err != nil {
        fmt.Println("Failed to change password:", err)
        return
    }
    fmt.Println("Password changed successfully:", msg.String())

    // Step 4: Verify the updated password by logging in
    fmt.Println("Logging in with the updated password...")
    p4api.SetPassword("updated_password")
    loginResult, err = p4api.RunLogin()
    if err != nil {
        fmt.Println("Failed to log in with updated password:", err)
        return
    }
    fmt.Println("Login successful with updated password:", loginResult)

    // Step 5: Delete the password
    fmt.Println("Deleting the password...")
    msg, err = p4api.RunPassword("updated_password", "")
    if err != nil {
        fmt.Println("Failed to delete password:", err)
        return
    }
    fmt.Println("Password deleted successfully:", msg.String())

Your search for returned results