New Project (#206)

* Added folder locker and hider

* Update README.md
This commit is contained in:
Prajjwal Pathak 2021-04-16 22:57:13 +05:30 committed by GitHub
parent 57f28b44e4
commit 33935f573e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 347 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

View File

@ -0,0 +1,223 @@
import locker
import os
import tkinter as tk
from tkinter import PhotoImage
from tkinter import messagebox
from tkinter import filedialog
cwd = os.getcwd()
if not os.path.exists('files/'):
os.mkdir('files')
class Application(tk.Frame):
def __init__(self, master):
super().__init__(master=master)
self.master = master
self.pack()
self.title_frame()
self.main_frame()
self.status_frame()
self.folder_path = ''
self.fname = ''
def title_frame(self):
self.title = tk.Label(self, bg='gray',font=("Helvetica", 14), anchor='w')
self.title.configure(width=35, height=3)
self.title['text'] = '\t Folder Locker / Unlocker'
self.title.grid(row=0, column=0, columnspan=2)
def body_frame(self):
self.body = tk.Frame(self, width=390, height=230)
self.body.grid(row=1, column=0, columnspan=2, pady=10)
def status_frame(self):
self.status = tk.Text(self, width=50, height=3, fg='dodger blue')
self.status.insert(tk.END, 'The folder you lock will be hidden automatically\n')
self.status.insert(tk.END, 'Use the app to unlock it back')
self.status.configure(state='disabled')
self.status.grid(row=2, column=0, columnspan=2)
def main_frame(self):
self.body_frame()
self.lock_button = tk.Button(self.body, font =('Verdana', 15), command=self.lock_frame)
self.lock_button['image'] = lock_icon
self.lock_button['compound'] = tk.TOP
self.lock_button['text'] = 'Lock \nFolder'
self.lock_button.configure(width=120, height=120)
self.lock_button.grid(row=0, column=0, padx=(0,30), pady=(20,7))
self.unlock_button = tk.Button(self.body, font =('Verdana', 15), command=self.unlock_frame)
self.unlock_button['image'] = unlock_icon
self.unlock_button['compound'] = tk.TOP
self.unlock_button['text'] = ' Unlock \nFolder'
self.unlock_button.configure(width=120, height=120)
self.unlock_button.grid(row=0, column=1, padx=(30,0), pady=(20,7))
def lock_frame(self):
self.body.destroy()
self.body_frame()
self.status.configure(state='normal')
self.status.delete(1.0, tk.END)
self.status.insert(tk.END, 'Choose a folder, enter password and click lock\n')
self.status.insert(tk.END, 'folder to lock and hide the folder')
self.status.configure(state='disabled')
self.password = tk.StringVar()
self.pathlabel = tk.Label(self.body, bg='white', fg='black',
borderwidth=1, relief='groove', wraplength=150)
self.pathlabel['text'] = 'Select Folder'
self.pathlabel.configure(width=22, height=3)
self.pathlabel.grid(row=0, column=0, pady=10, padx=15)
self.choose_folder = tk.Button(self.body, image=choose_folder_icon)
self.choose_folder['command'] = self.select_folder
self.choose_folder.grid(row=0, column=1, padx=(20,5), pady=10)
self.back = tk.Button(self.body, image=back_icon)
self.back['command'] = self.go_back
self.back.grid(row=0, column=2, padx=(20,5), pady=10)
self.elabel = tk.Label(self.body, anchor='e')
self.elabel['text'] = 'Enter Password'
self.elabel.grid(row=1, column=0, pady=20)
self.entry = tk.Entry(self.body)
self.entry['textvariable'] = self.password
self.entry.grid(row=1, column=1, columnspan=2, pady=20)
self.lock =tk.Button(self.body, bg='green', width=20)
self.lock['text'] = f'Lock Folder'
self.lock['command'] = lambda : self.lock_folder(self.folder_path)
self.lock.grid(row=2, column=0, columnspan=3)
def unlock_frame(self):
self.body.destroy()
self.body_frame()
self.password = tk.StringVar()
self.pathlabel = tk.Label(self.body, bg='white', fg='black',
borderwidth=1, relief='groove', wraplength=150)
self.pathlabel['text'] = 'Select Folder'
self.pathlabel.configure(width=22, height=3)
self.pathlabel.grid(row=0, column=0, pady=2, padx=15)
self.back = tk.Button(self.body, image=back_icon)
self.back['command'] = self.go_back
self.back.grid(row=0, column=1, padx=(20,5), pady=2)
self.scrollbar = tk.Scrollbar(self.body, orient=tk.VERTICAL)
self.scrollbar.grid(row=0,column=3, rowspan=4, sticky='ns')
self.list = tk.Listbox(self.body, selectmode=tk.SINGLE,
yscrollcommand=self.scrollbar.set, selectbackground='sky blue')
self.list.config(height=10)
self.enumerate_folders()
self.list.bind('<Double-1>', self.get_folder)
self.scrollbar.config(command=self.list.yview)
self.list.grid(row=0, column=2, rowspan=4)
self.elabel = tk.Label(self.body, anchor='e')
self.elabel['text'] = 'Enter Password'
self.elabel.grid(row=1, column=0, columnspan=2, pady=(1,1))
self.entry = tk.Entry(self.body)
self.entry['textvariable'] = self.password
self.entry.grid(row=2, column=0, columnspan=2)
self.unlock =tk.Button(self.body, bg='green', width=20)
self.unlock['text'] = f'Unlock Folder'
self.unlock['command'] = lambda : self.unlock_folder(self.fname)
self.unlock.grid(row=3, column=0, columnspan=2, pady=(10,0))
def go_back(self):
self.body.destroy()
self.main_frame()
self.status.configure(state='normal')
self.status.delete(1.0, tk.END)
self.status.insert(tk.END, 'The folder you lock will be hidden automatically\n')
self.status.insert(tk.END, 'Use the app to unlock it back')
self.status.configure(state='disabled')
def select_folder(self):
self.folder_path = filedialog.askdirectory(initialdir=cwd)
self.pathlabel['anchor'] = 'w'
self.pathlabel['text'] = self.folder_path
def enumerate_folders(self):
self.dct = locker.read_json()
self.folders_list = list(self.dct.keys())
self.status.configure(state='normal')
self.status.delete(1.0, tk.END)
if len(self.folders_list) > 0:
for index, fname in enumerate(self.folders_list):
self.list.insert(index, fname)
self.status.insert(tk.END, 'Choose a folder, enter password and click unlock\n')
self.status.insert(tk.END, 'folder to unlock the folder')
else:
self.status.insert(tk.END, '0 folders locked yet\n')
self.status.configure(state='disabled')
def get_folder(self, event):
if event is not None:
self.current = self.list.curselection()[0]
self.folder_path = self.dct[self.folders_list[self.current]][0]
self.key = self.dct[self.folders_list[self.current]][1]
self.pathlabel['text'] = self.folder_path
def lock_folder(self, path):
password = self.entry.get()
if not self.folder_path == '':
if len(password) <= 4:
messagebox.showerror('Failed to lock', 'password is too short')
else:
status = locker.lock(self.folder_path, password)
if status == 'failed':
messagebox.showerror('Failed to lock', 'A folder with this name already locked')
else:
messagebox.showinfo('Folder status', 'Locked successfully')
self.password.set('')
self.pathlabel['anchor'] = 'c'
self.pathlabel['text'] = 'Select Folder'
def unlock_folder(self, fname):
password = self.entry.get()
if not self.folder_path == '':
if len(password) <= 4:
messagebox.showerror('Failed to unlock', 'password is too short')
else:
status = locker.unlock(self.folder_path, password, self.key)
if status == 'failed':
messagebox.showerror('Failed to unlock', 'Incorrect Password')
else:
messagebox.showinfo('Folder status', 'Folder unlocked successfully')
self.password.set('')
self.pathlabel['anchor'] = 'c'
self.pathlabel['text'] = 'Select Folder'
self.list.delete(0, tk.END)
self.enumerate_folders()
if __name__ == '__main__':
root = tk.Tk()
root.geometry('400x305')
root.title('Folder Locker/Unlocker')
root.resizable(0,0)
lock_icon = PhotoImage(file='icons/lock.png').subsample(2,2)
unlock_icon = PhotoImage(file='icons/unlock.png').subsample(2,2)
back_icon = PhotoImage(file='icons/back.png')
choose_folder_icon = PhotoImage(file='icons/choose_folder.png')
app = Application(master=root)
app.mainloop()

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

View File

@ -0,0 +1,84 @@
import os
import json
import shelve
import random
import subprocess
def read_json():
json_file = 'files/locked_folders.json'
if os.path.exists(json_file):
with open(json_file, 'r') as file:
dct = json.load(file)
else:
dct = {}
return dct
def write_to_json(data):
json_file = 'files/locked_folders.json'
with open(json_file, 'w') as file:
json.dump(data, file)
def get_from_json(fname):
dct = read_json()
return dct.get(fname, None)
# Locker/Unlocker ----------------------------------------------------------------
def generate_key():
string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
keygen = random.sample(string, 12)
return ''.join(keygen)
def lock(fpath, password):
key = generate_key()
fname = os.path.basename(fpath)
cwd = '/'.join(fpath.split('/')[:-1]) + '/'
command1 = 'ren ' + fname + ' "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}"'
command2 = 'attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}"'
dct = read_json()
if not fname in dct.keys():
dct[fname] = [fpath, key]
write_to_json(dct)
with shelve.open('files/pwd') as pwd_manager:
pwd_manager[fname] = password
subprocess.call(command1, shell=True, cwd=cwd)
subprocess.call(command2, shell=True, cwd=cwd)
status = 'locked'
else:
status = 'failed'
return status
def unlock(fpath, password, key):
fname = os.path.basename(fpath)
cwd = '/'.join(fpath.split('/')[:-1]) + '/'
command1 = 'attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}"'
command2 = 'ren "Control Panel.{21EC2020-3AEA-1069-A2DD-' + key + '}" ' + fname
with shelve.open('files/pwd') as pwd_manager:
pass_ = pwd_manager[fname]
if pass_ == password:
dct = read_json()
del dct[fname]
write_to_json(dct)
subprocess.call(command1, shell=True, cwd=cwd)
subprocess.call(command2, shell=True, cwd=cwd)
with shelve.open('files/pwd') as pwd_manager:
del pwd_manager[fname]
status = 'unlocked'
else:
status = 'failed'
return status

View File

@ -0,0 +1,39 @@
# Folder Locker & Hider
[![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](https://forthebadge.com)
[![forthebadge](https://forthebadge.com/images/badges/made-with-python.svg)](https://forthebadge.com)
Folder Locker & Hider is a simple python tkinter based application to lock / unlock and hide folders
using simple windows property
![Alt text](app.png?raw=true "Folder Locker & Hider")
This app is only for windows platform
## How to Download
Download this project from here [Download Folder Locker & Hider](https://downgit.github.io/#/home?url=https://github.com/pyGuru123/Tkinter-Applications/tree/master/Folder%20Locker%20%26%20Hider)
## Requirements
No external package is required
## Usage
Double click the application.pyw script to open the GUI application, then
to lock folder:
click the lock folder button, select the folder that you want to lock, enter a password and then click lock folder button to lock the folder, the folder will now be hidden automatically.
password should be greater than 4 digits in length, the locked folder can only be unlocked by using this app, also the folder will not show wven when show hidden items is checked
to unlock folder:
click the unlock folder button, select the locked folder name from the listbox on the right [double click it], then enter the correct password and unlock it by click the unlock folder button.
The folder will now be unhidden automatically
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.

View File

@ -172,6 +172,7 @@ So far, the following projects have been integrated to this repo:
|[GithubBot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/GithubBot)|[Abhilasha](https://github.com/Abhilasha06)| |[GithubBot](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/GithubBot)|[Abhilasha](https://github.com/Abhilasha06)|
|[Translate CLI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/TranslateCLI)|[Rodrigo Oliveira](https://github.com/rodrigocam)| |[Translate CLI](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/TranslateCLI)|[Rodrigo Oliveira](https://github.com/rodrigocam)|
|[Rock-Paper-Scissor Game](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Rock-Paper-Scissor)|[Punit Sakre](https://github.com/punitsakre23)| |[Rock-Paper-Scissor Game](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Rock-Paper-Scissor)|[Punit Sakre](https://github.com/punitsakre23)|
|[Folder Locker and hider](https://github.com/hastagAB/Awesome-Python-Scripts/tree/master/Folder%20Locker%20%26%20Hider)|[Prajjwal Pathak](https://github.com/pyguru123)|
## How to use : ## How to use :