{"id":18051791,"url":"https://github.com/joegasewicz/password-mixin","last_synced_at":"2025-04-10T18:15:39.184Z","repository":{"id":50217131,"uuid":"372519778","full_name":"joegasewicz/password-mixin","owner":"joegasewicz","description":"Small Python library that adds password hashing methods to ORM objects","archived":false,"fork":false,"pushed_at":"2021-11-26T02:28:02.000Z","size":46,"stargazers_count":8,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-06T09:59:14.698Z","etag":null,"topics":["crypto","hashing-algorithm","orm","password-hashing","passwords"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joegasewicz.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-05-31T13:40:21.000Z","updated_at":"2025-02-27T09:52:22.000Z","dependencies_parsed_at":"2022-09-26T20:52:39.579Z","dependency_job_id":null,"html_url":"https://github.com/joegasewicz/password-mixin","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joegasewicz%2Fpassword-mixin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joegasewicz%2Fpassword-mixin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joegasewicz%2Fpassword-mixin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joegasewicz%2Fpassword-mixin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joegasewicz","download_url":"https://codeload.github.com/joegasewicz/password-mixin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247974594,"owners_count":21026742,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crypto","hashing-algorithm","orm","password-hashing","passwords"],"created_at":"2024-10-30T22:56:02.160Z","updated_at":"2025-04-10T18:15:39.166Z","avatar_url":"https://github.com/joegasewicz.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Upload Python Package](https://github.com/joegasewicz/password-mixin/actions/workflows/python-publish.yml/badge.svg)](https://github.com/joegasewicz/password-mixin/actions/workflows/python-publish.yml)\n[![Python package](https://github.com/joegasewicz/password-mixin/actions/workflows/python-package.yml/badge.svg)](https://github.com/joegasewicz/password-mixin/actions/workflows/python-package.yml)\n\n# Password Mixin\nMixin that adds some useful methods to ORM objects\n\nCompatible with Python `3.5 \u003e`\n\n# Install\n```bash\npip install password-mixin\n```\n\n## Setup\nfirst create your objects (or ORM model) and add a `__hash_secret__` meta field.\nAssign your application's secret value to `__hash_secret__`.\n\n```python\n\nfrom password_mixin import PasswordMixin\nfrom sqlalchemy import Model # or Django , Flask-Sqlalchemy... etc.\n\nclass UserModel(OrmModel, PasswordMixin):\n    \n    password = Column(String()) # you must have a `password`.\n    \n    \n    # Now create a meta field to define the secret used to create the salt, for example:\n    __hash_secret__ = \"your-app-secret\"\n        \n```\n\n## Usage\nThe password is saved as the following: `\"\u003chash_name\u003e:\u003chash\u003e\"`\n\n### Password Hashing\n```python\nfrom password_mixin import PasswordAttributeError\ntry:\n    user = UserModel()\n    user.password = \"wizard123\"\n    user.hash_password() # password is now `sha256:7ac5cf88e8c9d262b49af168d9c30e47f2945cc9c207f20af0a39f09aa04595e`\n    # Now you can save your user to your db etc.\nexcept PasswordAttributeError:\n    # handle no password attribute\n    \n\n```\n\n### Validating Passwords\n```python\nfrom password_mixin import PasswordMatchError\n\ntry:\n    user.check_password(\"wizard111\")\nexcept PasswordMatchError:\n     # handle passwords don't match\n```\n\n### Example with Flask \u0026 Flask-Sqlalchemy\n```python\nclass UserModel(db.Model, PasswordMixin):\n\n    __tablename__ = \"users\"\n    __hash_secret__ = \"wizard123\"\n\n    id = db.Column(db.Integer, primary_key=True)\n    email = db.Column(db.String(100), nullable=False)\n    password = db.Column(db.String(100), nullable=False)\n\n    def create_user(self):\n        self.hash_password()\n        db.session.add(self)\n```\nNow, with the above setup you can run the following\n\n```python\nu = UserModel(email=\"test1@test.com\", password=\"wizard123\")\nu.create_user()\ndb.session.commit()\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoegasewicz%2Fpassword-mixin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoegasewicz%2Fpassword-mixin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoegasewicz%2Fpassword-mixin/lists"}