Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow password change via container CLI #1863

Merged
merged 3 commits into from
Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/docs/documentation/getting-started/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,13 @@ docker exec -it mealie-next bash

python /app/mealie/scripts/reset_locked_users.py
```

## How can I change my password

You can change your password by going to the user profile page and clicking the "Change Password" button. Alternatively you can use the following script to change your password via the CLI if you are locked out of your account.

```shell
docker exec -it mealie-next bash

python /app/mealie/scripts/change_password.py
```
40 changes: 40 additions & 0 deletions mealie/scripts/change_password.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from getpass import getpass

from mealie.core import root_logger
from mealie.core.security.security import hash_password
from mealie.db.db_setup import session_context
from mealie.repos.repository_factory import AllRepositories


def main():
confirmed = input("Please enter the email of the user you want to reset: ")

logger = root_logger.get_logger()

with session_context() as session:
repos = AllRepositories(session)

user = repos.users.get_one(confirmed, "email")

if not user:
logger.error("no user found")
exit(1)

logger.info(f"changing password for {user.username}")

pw = getpass("Please enter the new password: ")
pw2 = getpass("Please enter the new password again: ")

if pw != pw2:
logger.error("passwords do not match")

hashed_password = hash_password(pw)
repos.users.update_password(user.id, hashed_password)

logger.info("password change successful")
input("press enter to exit ")
exit(0)


if __name__ == "__main__":
main()