Mavhas commited on
Commit
f33e4d1
·
verified ·
1 Parent(s): 11b17ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -4
app.py CHANGED
@@ -3,9 +3,9 @@ from datetime import datetime
3
  import json
4
  import os
5
 
6
- # File to store diary entries
7
  DATA_FILE = "diary_entries.json"
8
- PASSWORD = "diary123" # Default password (can be customized)
9
 
10
  # Load existing diary entries
11
  def load_entries():
@@ -19,6 +19,18 @@ def save_entries(entries):
19
  with open(DATA_FILE, "w") as file:
20
  json.dump(entries, file, indent=4)
21
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  # Password verification
23
  def verify_password():
24
  if "password_verified" not in st.session_state:
@@ -27,7 +39,7 @@ def verify_password():
27
  if not st.session_state.password_verified:
28
  password_input = st.text_input("Enter Password:", type="password")
29
  if st.button("Submit"):
30
- if password_input == PASSWORD:
31
  st.session_state.password_verified = True
32
  st.success("Password verified!")
33
  else:
@@ -35,6 +47,22 @@ def verify_password():
35
  return False
36
  return True
37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  # Main app function
39
  def main():
40
  st.set_page_config(page_title="My Secret Diary", page_icon="📔", layout="centered")
@@ -50,7 +78,7 @@ def main():
50
 
51
  # Sidebar for navigation
52
  st.sidebar.title("Navigation")
53
- option = st.sidebar.radio("Choose an option:", ["Add Entry", "View Entries"])
54
 
55
  if option == "Add Entry":
56
  st.subheader("Add a New Diary Entry")
@@ -72,5 +100,8 @@ def main():
72
  st.write(f"**Entry for {selected_entry_key}:**")
73
  st.write(diary_entries[selected_entry_key])
74
 
 
 
 
75
  if __name__ == "__main__":
76
  main()
 
3
  import json
4
  import os
5
 
6
+ # File to store diary entries and password
7
  DATA_FILE = "diary_entries.json"
8
+ PASSWORD_FILE = "password.txt"
9
 
10
  # Load existing diary entries
11
  def load_entries():
 
19
  with open(DATA_FILE, "w") as file:
20
  json.dump(entries, file, indent=4)
21
 
22
+ # Load password
23
+ def load_password():
24
+ if os.path.exists(PASSWORD_FILE):
25
+ with open(PASSWORD_FILE, "r") as file:
26
+ return file.read().strip()
27
+ return "diary123" # Default password
28
+
29
+ # Save new password
30
+ def save_password(new_password):
31
+ with open(PASSWORD_FILE, "w") as file:
32
+ file.write(new_password)
33
+
34
  # Password verification
35
  def verify_password():
36
  if "password_verified" not in st.session_state:
 
39
  if not st.session_state.password_verified:
40
  password_input = st.text_input("Enter Password:", type="password")
41
  if st.button("Submit"):
42
+ if password_input == load_password():
43
  st.session_state.password_verified = True
44
  st.success("Password verified!")
45
  else:
 
47
  return False
48
  return True
49
 
50
+ # Change password
51
+ def change_password():
52
+ st.subheader("Change Password")
53
+ current_password = st.text_input("Enter Current Password:", type="password")
54
+ new_password = st.text_input("Enter New Password:", type="password")
55
+ confirm_password = st.text_input("Confirm New Password:", type="password")
56
+
57
+ if st.button("Change Password"):
58
+ if current_password != load_password():
59
+ st.error("Current password is incorrect.")
60
+ elif new_password != confirm_password:
61
+ st.error("New passwords do not match.")
62
+ else:
63
+ save_password(new_password)
64
+ st.success("Password changed successfully!")
65
+
66
  # Main app function
67
  def main():
68
  st.set_page_config(page_title="My Secret Diary", page_icon="📔", layout="centered")
 
78
 
79
  # Sidebar for navigation
80
  st.sidebar.title("Navigation")
81
+ option = st.sidebar.radio("Choose an option:", ["Add Entry", "View Entries", "Change Password"])
82
 
83
  if option == "Add Entry":
84
  st.subheader("Add a New Diary Entry")
 
100
  st.write(f"**Entry for {selected_entry_key}:**")
101
  st.write(diary_entries[selected_entry_key])
102
 
103
+ elif option == "Change Password":
104
+ change_password()
105
+
106
  if __name__ == "__main__":
107
  main()