Using ADB to change the screen lock

by MishaP   Last Updated April 16, 2018 10:11 AM

I am looking for a way to change the screen lock type from slide to password, and set the password via adb command line. I have a device with the setup I want, and one that has slide lock. I'm pretty sure this can be accomplished via sqlite3 "copy paste" of some fields, but not sure which fields, and how to do it. I'm open to pretty much all ideas except using adb shell input commands to accomplish this. Meaning - I can/know how to/am currently using commands input swipe input text input tap commands to change swipe unlock to password unlock.

edit1: clarified adb shell input, and yes, my phone is rooted.

edit2: relevant links:
How to change lock screen type
Pass encryption on android

According to the post in the first link, it should be easy to change the lockscreen type, the only problem is that I cannot find the lockscreen.password_type field in the database they refer to. Has it moved in 4.3? After reading through the article in the second link my idea became to use the salt number stored in the database to hash out a new password using the device specific salt, and override the existing (if any) password. I'm still trying to figure out how to do this.

Tags : adb lock-screens


Answers 2


There's no built-in functionality to set the password via the command-line, neither from a shell on the device nor from adb. You can't even achieve this by pasting the stored password into the secure settings file from another device. The password isn't stored as plain text, but rather a cryptographic hash of the password is stored. This hash is generated using the password and a salt value: a random number generated once on the device.

Hashing the password prevents someone from stealing your phone and finding the password. This is important not just to protect the password itself (in case you use the same password for other things), but also because the password is used to encrypt the device's key store, and as part of the full-device encryption feature. Salting the password with a device-specific salt ensures an attacker can't use a rainbow table to determine the password. (A rainbow table is a list of every possible hashed password, which one queries to find the original password given the hashed password. The technique allows naïve password implementations such as Windows 95's to be broken in less than a second using a normal desktop computer.)

In addition, the code that updates the stored password when you change it through the GUI has other side-effects. As I've mentioned, the password is used to encrypt the device's key store, which can be used by all apps on the device to store credentials securely. Changing the saved password without updating the key store would result in the stored credentials being lost. In addition, if full-device encryption is used, changing the saved password without updating the device encryption key would result in all storage becoming inaccessible.

To achieve the functionality you want, the easiest way would be to patch a custom ROM to export the functionality that the settings app uses to change the password, and add a command-line program that can change the password in the same way. It might even be possible to hack up an app that can do this using reflection to get access to the un-exported functions, but the app would still need root, and it would be specific to the ROM (and maybe even the version of the ROM) on the device.

The relevant code is here if you're interested.

Dan Hulme
Dan Hulme
August 13, 2013 22:11 PM

you can the password using below adb commands

adb shell

athene_f:/ $ locksettings
usage: locksettings set-pattern [--old OLD_CREDENTIAL] NEW_PATTERN

   locksettings set-pin [--old OLD_CREDENTIAL] NEW_PIN
   locksettings set-password [--old OLD_CREDENTIAL] NEW_PASSWORD
   locksettings clear [--old OLD_CREDENTIAL]
   locksettings verify [--old OLD_CREDENTIAL]
   locksettings set-disabled DISABLED
   locksettings get-disabled

flags: --user USER_ID: specify the user, default value is current user

  1. locksettings set-pin: sets a PIN

  2. locksettings set-password: sets a password

  3. locksettings clear: clears the unlock credential

  4. locksettings verify: verifies the credential and unlocks the user

  5. locksettings set-disabled: sets whether the lock screen should be disabled

  6. locksettings get-disabled: retrieves whether the lock screen is disabled

and if you want to remove password just use below code .

 $ locksettings clear --old old_password_put_here

here is reference link :https://www.theandroidsoul.com/change-remove-lockscreen-pattern-pin-password-adb-android-oreo/

i have tested on android Oreo device.it work just fine.

Rk215 Tech
Rk215 Tech
April 16, 2018 09:34 AM

Related Questions