{"id":37073712,"url":"https://github.com/williamburriss/flask_app_security","last_synced_at":"2026-01-14T08:39:19.628Z","repository":{"id":190703908,"uuid":"682693248","full_name":"williamburriss/flask_app_security","owner":"williamburriss","description":"Provides utilities for securing passwords and handling user sessions.","archived":false,"fork":false,"pushed_at":"2023-08-25T22:50:27.000Z","size":35,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-16T01:31:11.826Z","etag":null,"topics":["django","flask","python"],"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/williamburriss.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-24T18:11:54.000Z","updated_at":"2023-08-25T22:35:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"43d459a4-b66d-4888-a079-074b5c5fd5e4","html_url":"https://github.com/williamburriss/flask_app_security","commit_stats":null,"previous_names":["williamburriss/flask_app_security"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/williamburriss/flask_app_security","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamburriss%2Fflask_app_security","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamburriss%2Fflask_app_security/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamburriss%2Fflask_app_security/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamburriss%2Fflask_app_security/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/williamburriss","download_url":"https://codeload.github.com/williamburriss/flask_app_security/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/williamburriss%2Fflask_app_security/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28414670,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T08:38:59.149Z","status":"ssl_error","status_checked_at":"2026-01-14T08:38:43.588Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["django","flask","python"],"created_at":"2026-01-14T08:39:18.797Z","updated_at":"2026-01-14T08:39:19.615Z","avatar_url":"https://github.com/williamburriss.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# flask_app_security\n\nCreated by William Burriss\n\nProvides utilities for securing passwords and handling user sessions.\n\n### Dependencies\n\n    - joserfc\n\n\n# - password_utils -\n#### module: flask_app_security.password_utils\n\n## secure_password\n\n```\n(function) def secure_password(password: str) -\u003e Secured_Password\n```\n\nSecures a password by generating a random string of \"salt\"\nand then hashing the password+salt. This is done to prevent\nduplicate passwords from having the same hash. A login_token\nis also generated. This should be stored !!SECURELY!! on the\nclient side for the use of remembering the user. \n\nExample:\n```\nfrom flask_app_security.password_utils import secure_password\n\npassword = \"my_password\"\nsecured_password_string = secure_password(password).to_string()\n```\n\n## validate_password\n\n```\n(function) def validate_password(\n    password: str,\n    _secured_password: Any\n) -\u003e (bool | Any)\n```\n\nTakes a plain text password and a Secured_Password and returns\nif the password is correct.\n\nNote: the Secured_Password can either be an instance of\nSecured_Password OR it can be the string returned from\nSecured_Password's to_string() method\n\nExample:\n```\nfrom flask_app_security.password_utils import secure_password, validate_password\n\nsecured_password = secure_password(\"password\")\nstring = secured_password.to_string()\n\nvalidate_password(\"password\", secured_password) # True\nvalidate_password(\"password\", string) # True\n\nvalidate_password(\"password wrong\", secured_password) # False\nvalidate_password(\"password wrong\", string) # False\n```\n\n## validate_login_token\n\n```\n(function) def validate_login_token(\n    login_token: str,\n    _secured_password: Any\n) -\u003e (bool | Any)\n```\n\nTakes a plain login_token and a Secured_Password and returns\nif the login_token is correct.\n\nNote: the Secured_Password can either be an instance of\nSecured_Password OR it can be the string returned from\nSecured_Password's to_string() method\n\nExample:\n```\nfrom flask_app_security.password_utils import secure_password, validate_login_token\n\nsecured_password = secure_password(\"password\")\ntoken = secured_password.login_token\nstring = secured_password.to_string()\n\nvalidate_login_token(token, secured_password) # True\nvalidate_login_token(token, string) # True\n\nvalidate_login_token(\"invalid token\", secured_password) # False\nvalidate_login_token(\"invalid token\", string) # False\n```\n\n## Secured_Password\n\n\n```\n(class) Secured_Password\n```\n\n* ```(method) def __init__(self: Self@Secured_Password, password_hash: Any, salt: Any, login_token: Any) -\u003e None```\n\nConstructor\n\n* ```(method) def to_string(self: Self@Secured_Password) -\u003e str```\n\nCreates a string that can be stored in a database.\nThis string can later be used to create another\ninstance of Secured_Password using its static\nfrom_string() method.\n\n* ```(staticmethod) def from_string(string: str) -\u003e Secured_Password```\n\nCreates a Secured_Password instance from a string.\nUsed to convert the string returned by this class'\nto_string() method back into a Secured_Password.\n\n# - session_utils -\n#### module: flask_app_security.session_utils\n\n## encode_dict\n\n```\n(function) def encode_dict(\n    d: dict,\n    secret_key: str,\n    valid_time_ms: float = -1\n) -\u003e str\n```\n\nEncodes a python dictionary provided a secret key used to\nencode. Takes optional parameter for creating a timed\nencode. Meaning the encoded dict will have an expiriation.\nThis is done by passing the time in ms as the third \nparameter. If no 3rd parameter or -1 is passed, no time\nwill be set and the encoded dict will not expire.\n\nExample:\n```\nfrom flask_app_security.session_utils import encode_dict\n\nsecret_key = \"my_secret_key\"\ntest_dict = {\n    \"username\": \"my_username\",\n    \"email\": \"myemail@test.com\",\n    \"user_id\": 123456789\n}\n\nencoded_dict = encode_dict(test_dict, secret_key)\n\nvalid_until = 10 * 1000 # 10 seconds (as ms)\n\nencoded_dict_timed = encode_dict(test_dict, secret_key, valid_until)\n```\n\n## decode_dict\n\n```\n(function) def decode_dict(\n    string: str,\n    secret_key: str\n) -\u003e dict\n```\n\nDecodes dict. Works with both timed and non-timed encodes.\nReturns None if expired or if invalid secret_key is given.  \n\nExample:\n```\nfrom flask_app_security.session_utils import encode_dict, decode_dict\n\nsecret_key = \"my_secret_key\"\ntest_dict = {\n    \"username\": \"my_username\",\n    \"email\": \"myemail@test.com\",\n    \"user_id\": 123456789\n}\n\nt = 2 * 1000 # 2 seconds (as ms)\n\nencoded_dict = encode_dict(test_dict, secret_key, t)\ndecoded_dict = decode_dict(encoded_dict, secret_key) # {\"username\": \"my_username\", \"email\": \"myemail@test.com\", \"user_id\": 123456789}\ndecoded_dict = decode_dict(encoded_dict, \"incorrect_secret_key\") # None\n\ntime.sleep(2.1) # sleeps for 2 seconds, so that the encoded dict will have expired\n\ndecoded_dict = decode_dict(encoded_dict, secret_key) # None\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamburriss%2Fflask_app_security","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwilliamburriss%2Fflask_app_security","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwilliamburriss%2Fflask_app_security/lists"}