Passwords
Passwords are 6 to 60 characters.
Changing the password
A signed-in user changes their password with changePassword(), giving the current one and the new one.
import com.skapi.Skapi
import com.skapi.SkapiException
val skapi = Skapi("<Project ID>")
skapi.login("user@example.com", "password")
try {
println(skapi.changePassword("password", "new password")) // SUCCESS: Password has been changed.
} catch (err: SkapiException) {
if (err.code == "INVALID_REQUEST") {
println(err.message) // Incorrect password.
} else {
throw err
}
}import com.skapi.SkapiException;
import com.skapi.java.SkapiJava;
import java.util.concurrent.ExecutionException;
SkapiJava skapi = new SkapiJava("<Project ID>");
skapi.login("user@example.com", "password").get();
try {
System.out.println(skapi.changePassword("password", "new password").get()); // SUCCESS: Password has been changed.
} catch (ExecutionException e) {
SkapiException err = (SkapiException) e.getCause();
if ("INVALID_REQUEST".equals(err.getCode())) {
System.out.println(err.getMessage()); // Incorrect password.
} else {
throw err;
}
}Forgot password
A user who cannot log in resets the password in two steps. The reset code is always sent by e-mail, so a user whose e-mail is not verified may not receive it. Encourage users to verify their e-mail.
Step 1: send the code
forgotPassword() e-mails a reset code to the account.
println(skapi.forgotPassword("user@example.com")) // SUCCESS: Verification code has been sent.System.out.println(skapi.forgotPassword("user@example.com").get()); // SUCCESS: Verification code has been sent.To use one of your project's uploaded templates for this e-mail, pass its message ID: forgotPassword("user@example.com", jsonOf("forgot_password" to "<message_id>")).
Step 2: set the new password
resetPassword() takes the e-mail, the code from the e-mail, and the new password.
println(skapi.resetPassword("user@example.com", "123456", "new password"))
// SUCCESS: New password has been set.System.out.println(skapi.resetPassword("user@example.com", "123456", "new password").get());
// SUCCESS: New password has been set.With record encryption on, a reset cannot open the user's encrypted records: they were locked with the old password. After the reset, the user signs in with the new password and, once, calls unlockEncryptionWithRecoveryCode(code, newPassword) with their encryption recovery code; it returns a new code to show them, and the code just used stops working. The same goes for an account that also signs in with OpenID: with encryption on, it signs in with login() and the new password from then on. A password change while signed in (changePassword()) never needs the code. See When the recovery code is needed.
A user who signs in with OpenID can set a password of their own the same way. In an app with encryption off, it keeps working next to OpenID sign-in when the reset code went to the e-mail the OpenID provider shares. After a reset whose code went to another e-mail, the account's existing sessions stop being renewed, so the user signs in again, and in an app with encryption off the next OpenID sign-in from 2.8.0 takes the account over again (with merge if it throws ACCOUNT_EXISTS), which replaces that password and signs the account out on every device. With encryption on, OpenID sign-in is refused after a reset and the user signs in with login(). A reset that finishes while an OpenID sign-in is being completed makes that sign-in throw INVALID_REQUEST (The account changed during the OpenID sign-in. Please try again.); signing in again works. See OpenID Login.
Resetting the password does not turn off two-step login. It does sign the account out on every other device: each one is signed out the next time it refreshes its login (within a day at most).
