Share via


DevicePolicyManager.ResetPassword(String, ResetPasswordFlags) Method

Definition

Force a new password for device unlock (the password needed to access the entire device) or the work profile challenge on the current user.

[Android.Runtime.Register("resetPassword", "(Ljava/lang/String;I)Z", "GetResetPassword_Ljava_lang_String_IHandler")]
public virtual bool ResetPassword (string? password, Android.App.Admin.ResetPasswordFlags flags);
[<Android.Runtime.Register("resetPassword", "(Ljava/lang/String;I)Z", "GetResetPassword_Ljava_lang_String_IHandler")>]
abstract member ResetPassword : string * Android.App.Admin.ResetPasswordFlags -> bool
override this.ResetPassword : string * Android.App.Admin.ResetPasswordFlags -> bool

Parameters

password
String

The new password for the user. Null or empty clears the password.

flags
ResetPasswordFlags

May be 0 or combination of #RESET_PASSWORD_REQUIRE_ENTRY and #RESET_PASSWORD_DO_NOT_ASK_CREDENTIALS_ON_BOOT.

Returns

Returns true if the password was applied, or false if it is not acceptable for the current constraints.

Attributes

Remarks

Force a new password for device unlock (the password needed to access the entire device) or the work profile challenge on the current user. This takes effect immediately.

Before android.os.Build.VERSION_CODES#N, this API is available to device admin, profile owner and device owner. Starting from android.os.Build.VERSION_CODES#N, legacy device admin (who is not also profile owner or device owner) can only call this API to set a new password if there is currently no password set. Profile owner and device owner can continue to force change an existing password as long as the target user is unlocked, although device owner will not be able to call this API at all if there is also a managed profile on the device.

Between android.os.Build.VERSION_CODES#O, android.os.Build.VERSION_CODES#P and android.os.Build.VERSION_CODES#Q, profile owner and devices owner targeting SDK level android.os.Build.VERSION_CODES#O or above who attempt to call this API will receive SecurityException; they are encouraged to migrate to the new #resetPasswordWithToken API instead. Profile owner and device owner targeting older SDK levels are not affected: they continue to experience the existing behaviour described in the previous paragraph.

<em>Starting from android.os.Build.VERSION_CODES#R, this API is no longer supported in most cases.</em> Device owner and profile owner calling this API will receive SecurityException if they target SDK level android.os.Build.VERSION_CODES#O or above, or they will receive a silent failure (API returning false) if they target lower SDK level. For legacy device admins, this API throws SecurityException if they target SDK level android.os.Build.VERSION_CODES#N or above, and returns false otherwise. Only privileged apps holding RESET_PASSWORD permission which are part of the system factory image can still call this API to set a new password if there is currently no password set. In this case, if the device already has a password, this API will throw SecurityException.

The given password must be sufficient for the current password quality and length constraints as returned by #getPasswordQuality(ComponentName) and #getPasswordMinimumLength(ComponentName); if it does not meet these constraints, then it will be rejected and false returned. Note that the password may be a stronger quality (containing alphanumeric characters when the requested quality is only numeric), in which case the currently active quality will be increased to match.

On devices not supporting PackageManager#FEATURE_SECURE_LOCK_SCREEN feature, this methods does nothing.

The calling device admin must have requested DeviceAdminInfo#USES_POLICY_RESET_PASSWORD to be able to call this method; if it has not, a security exception will be thrown.

This member is deprecated. Please use #resetPasswordWithToken instead.

Java documentation for android.app.admin.DevicePolicyManager.resetPassword(java.lang.String, int).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to