[FIX] Wrong Pin/Pattern when restoring TWRP Nandroid Backup


When you create and restore a TWRP backup (as example because you tried out a custom ROM and saw that it’s not good) you’ll be greeted with:

a) A “enter PIN before boot” screen
b) A wrong lockscreen code (either PIN or Pattern) when booted to Android

————————
HOW TO FIX
————————

  1. Simply boot into TWRP and enter your PIN (if you’ve set one) to decrypt the stroage. If you don’t have TWRP (for whatever reason) you can do so via ADB too but ONLY if you’ve connected your phone to your PC beforehand and also accepted it’s fingerprint on the phone itself.
  2. Delete (or rename) the following files inside /data/system (note that probably not all of them exist for you, simply delete those you can find):
    • password.key
    • pattern.key
    • locksettings.db-wal
    • locksettings.db-shm
    • locksettings.db
  3. Reboot the phone and (if you’ve set a PIN) enter it to decrypt the storage one more time. After that you can simply unlock your phone with a swipe.
  4. Go into Settings > Security and set your preferred unlock method again, Android will ask you if you want to set a boot-time code too. Select whatever you want here, it’s a nice security addition but can be annoying sometimes.
  5. Enjoy your phone again!

I hope this helps some people here since I was searching on how to fix this for almost an hour after restoring a backup. This is probably due to another ROM overwriting existing lockdata when you set a code there, then again you’d wipe the /data partition anyways so I have no clue why it’s still acting up like this…