Skip to main content

check auth use mongodb

Project description

master-auth

check auth use mongodb

how to use

install

pip install master_auth

example

from master_auth import core
import os
import dotenv
dotenv.load_dotenv()

MONGODB_USER = os.getenv("MONGODB_USER")
MONGODB_PASSWORD = os.getenv("MONGODB_PASSWORD")
MONGODB_HOST = os.getenv("MONGODB_HOST")
MONGODB_PORT = os.getenv("MONGODB_PORT")
DATABASE_NAME =  os.getenv("APP_NAME") + os.getenv("MONGODB_DATABASE_NAME")
COLLECTION_NAME = "master_auth"

def save_password(username,password):
    result = core.save_password(
        mongodb_username=MONGODB_USER,
        mongodb_password=MONGODB_PASSWORD,
        mongodb_host=MONGODB_HOST,
        mongodb_port=MONGODB_PORT,
        database_name = DATABASE_NAME,
        collection_name = COLLECTION_NAME,
        username = username,
        password = password
    )

    if result:
        print("Password saved successfully!")
        return True
    else:
        print("Username already exists!")
        return False

def update_password(username,password_old,password_new):
    result = core.update_password(
        mongodb_username=MONGODB_USER,
        mongodb_password=MONGODB_PASSWORD,
        mongodb_host=MONGODB_HOST,
        mongodb_port=MONGODB_PORT,
        database_name = DATABASE_NAME,
        collection_name = COLLECTION_NAME,
        username = username,
        password_old = password_old,
        password_new = password_new
    )

    if result:
        print("Password updated successfully!")
        return True
    else:
        print("Old password is not correct!")
        return False

def verify_password(username,password):
    result = core.verify_password(
        mongodb_username=MONGODB_USER,
        mongodb_password=MONGODB_PASSWORD,
        mongodb_host=MONGODB_HOST,
        mongodb_port=MONGODB_PORT,
        database_name = DATABASE_NAME,
        collection_name = COLLECTION_NAME,
        username = username,
        password = password
    )

   if result:
        print("Password is correct!")
        return True
   else:
        print("Password is not correct!")
        return False

if __name__ == "__main__":
    save_password("test","test")
    # Username does not exist!
    # Password saved successfully!

    # update_password("test","test","test2")
    # Password updated successfully!

    # verify_password("test","test2")
    # Password is correct!

v0.0.2

  • update some bugs

v0.0.1

  • save password to mongodb , password is hashed
  • check password from mongodb , password is hashed
  • update password to mongodb , password is hashed

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

master_auth-0.0.2.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

master_auth-0.0.2-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file master_auth-0.0.2.tar.gz.

File metadata

  • Download URL: master_auth-0.0.2.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for master_auth-0.0.2.tar.gz
Algorithm Hash digest
SHA256 380479140a595610f0ea6b0dca91c6dd3cf3da2c6d7a531c43665320a9bb69d4
MD5 ed5c33097e62b66e0de52360b30588ca
BLAKE2b-256 a96dea8a263ba8678b4a6a8fe9d11a481318c85c8f2a8367078b05e056392a66

See more details on using hashes here.

File details

Details for the file master_auth-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: master_auth-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.12

File hashes

Hashes for master_auth-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 30bcdc450d5958505078bce0db4589879f073efad27e4e3c05bf2c843785fd66
MD5 ccaa427b67090a7d0cbefc8221024965
BLAKE2b-256 e39e30f992c3f2732adcb1cb4fb9db2a5752fb251e5d25a68c11f649022b0b65

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page