Ubuntu: Password protect changing wallpaper


In order to prevent someone (other than me) from changing my background, how can I make wallpaper changing an action requiring a password?


This turned out to be a nice challenge. Try,

$ sudo mv /usr/bin/gsettings /usr/bin/gsettings2  $ sudo gedit /usr/bin/gsettings  $ sudo chmod +x /usr/bin/gsettings  

When gedit comes up on the second instruction, add:

#!/bin/bash  if [ "$1" == "set" ] && [ "$2" == "org.gnome.desktop.background" ] && [ "$3" == "picture-uri" ]; then      a=$(zenity --entry="Password")      h1=$(/bin/echo $a | /usr/bin/md5sum | /bin/cut -f1 -d" ")      h2='a799d7cf3d9ca647f1320fc6bfaf7408' #Password hash      if [ "$h1" == "$h2" ]; then      gsettings2 set org.gnome.desktop.background picture-uri $4      else          zenity --notification --text="Wrong password. Come again another day"      fi  else      $(gsettings2 $@)  fi  

To undo,

$ sudo rm /usr/bin/gsettings  $ sudo mv /usr/bin/gsettings2 /usr/bin/gsettings  

You can go to this md5 generator, put your string and replace a799d7cf3d9ca647f1320fc6bfaf7408 with whatever you like. Try finding out for yourself what this corresponds. You'll realize how secure this is.

Even if somebody views this file, without your password they cannot change it (This is similar to how linux stores your passwords :P).


Password protect changing wallpaper

The script below provides a mild password protection for changing the wallpaper in "home" situations. Mild because the password is stored inside the script in plain text. Nevertheless it should prevent average users from changing the wallpaper.

What it does is that when a user changes the wallpaper, it changes back immediately, and the user is prompted for a password. If the password is correct, the wallpaper changes into the newly set one, otherwise nothing happens.

enter image description here

To minimize the risk, store the script in an unexpected place under an unexpected name, and /or as a hidden file.

To use it:

Copy the script below into an empty file, set a password of your choice in the head section (I wouldn't choose your sudo password for security reasons, since it is in plain text!) and save it as name.py, run it by the command:

python3 /path/to/name.py  

The script:

#!/usr/bin/env python3    import time  import subprocess    set_password = "monkey"    key = "org.gnome.desktop.background picture-uri "  read = "gsettings get "+key; change = "gsettings set "+key  set_wallpaper = subprocess.check_output(["/bin/bash", "-c", read]).decode("utf-8").strip()  pass_window ='zenity --entry --entry-text="Enter password" --text="Enter password" --title="password" --hide-text'    def check_wall():      global set_wallpaper      curr_wallpaper = subprocess.check_output(["/bin/bash", "-c", read]).decode("utf-8").strip()      if curr_wallpaper != set_wallpaper:          subprocess.Popen(["/bin/bash", "-c", change+set_wallpaper])          try:              entered_password = subprocess.check_output(                  ["/bin/bash", "-c", pass_window]).decode("utf-8").strip()          except Exception:              entered_password = None          if entered_password == set_password:              subprocess.Popen(["/bin/bash", "-c", change+curr_wallpaper])              set_wallpaper = curr_wallpaper      else:          pass    while True:      check_wall()      time.sleep(3)  

posted on gist.gisthub

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »