7

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.

0

2 Answers 2

17

Since Android 8.0 Oreo, you can change the lock screen 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 the password, just use below code:

$ locksettings clear --old old_password_put_here

Here is the reference link: The Android Soul - How to change or remove lock screen pattern, PIN or password via ADB on Android 8.0 Oreo

I have tested on Android Oreo device. It works just fine.

1
  • Getting response as Request Throttled. What does that mean? Commented Dec 1, 2021 at 6:34
4

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.

2
  • 1
    Well, the thing is I read this article: [forensics.spreitzenbarth.de/2012/02/28/… and it essentially tells you how to break open a password using the password.key file (this is the encrypted password?) and settings.db (stores the salt?) to brute force attack the password somehow (I don't know enough about encryption to fully comprehend this article). Based on this article I then came up with the idea of potentially using the device specific salt to encrypt a new pass, and overwrite password.key Flawed logic or possible?
    – MishaP
    Commented Aug 13, 2013 at 22:34
  • the article
    – MishaP
    Commented Aug 13, 2013 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .