Skip to main content

A collection of tools for user authentication and data management. The library is released under the MIT License and the documentation is generated by an AI trained by OpenAI.

Project description

Table of Contets

sixauth

sixauth is a collection of tools for user authentication and data management. The library is released under the MIT License and the documentation is generated by an AI trained by OpenAI.

The sixauth module provides a simple way to handle user authentication and data storage on a remote server or your local machine. The AuthSesh class allows you to sign up, log in, and manage their data in the database. For more details and examples, see the AuthSesh class documentation.

Installation

You can install sixauth using Python's built-in package manager:

$ pip install sixauth

Or by downloading this repo and moving the sixauth folder where its needed.

Usage

Instancing

To use the AuthSesh class, you first need to create an instance of the class. There are two ways to do this, with a context manager or without.

With Context Manager

The AuthSesh class can be used as a context manager:

from sixauth import AuthSesh with AuthSesh() as auth: # ...

This will automatically log out and terminate the session when the context ends.

Without Context Manager

The AuthSesh class can also be used without a context manager:

from sixauth import AuthSesh auth = AuthSesh() # ...

When you are done with the instance, you have to use the terminate() method to save your work and properly close connections:

auth.terminate()

IMPORTANT: If you do not do this, nothing you do will save.

Remote or Local Connections

When creating a AuthSesh instance there are a few options for where the instance will connect to. You can only pick from one of these, if you provide an address and a path, it will connect to the server and disreguard the path given.

Current Working Directory

The simplest is connecting to a database in the current working directory of your script:

AuthSesh()

This will create a database.db file in the current working directory if one is not already there.

Local Folder

Next is connecting to a database in a path specified as a paramater:

AuthSesh(Path="pathto/database/folder")

This will create a database.db file in the specified path if one is not already there, it will not make the folder if it doesnt exsist though.

Servers

Lastly, connecting to a remote server:

AuthSesh(Address="0.0.0.0:5678")

This will establish a secure connection to the remote server provided. If you want to host a server look at Hosting a Server.

Setting Values

In order to authenticate a user we need their name and password. You do that with the set_vals() method:

auth.set_vals("username", "password")

You can call this method at anytime to change the user. However if login() is not called before attempting to manage data, it will still be connected to the previous user.

Signing Up

Once a username and password are set, you use the signup() method to sign up:

auth.signup()

If the signup is successful, you then have to login to actually manage user data.

Logging In

Once you're ready to login, you can use the login() method to log in to the server:

auth.login()

If the login is successful, you can start managing the database.

Saving Data

After you've seccessfully logged in, you use the save() mathod to save data into the database:

auth.save("user_data/profile", {"name": "John Doe", "email": "johndoe@example.com"})

Data in the database is stored in a dictonary and parsed based on the the path provided.

Loading Data

You access data in the database with the load() method:

data = auth.load("user_data/profile")

This will will return the data in the specified location, if no location is provided, it will return the whole dictionary.

Deleting Data

To delete data in the database, you use the delete() method:

auth.delete("user_data/profile")

Removing User

Finally, if you'd like to delete the user from the database, you use the remove() method:

auth.remove()

Exceptions

The AuthSesh class raises the following exceptions:

  • AuthenticationError: Raised if there is an error authenticating the user.
  • DataError: Raised if there is an error accessing or modifying the data on the server.
  • LocationError: Raised if the specified location does not exist on the server.
  • PasswordError: Raised if the password is incorrect or invalid.
  • UsernameError: Raised if the username is invalid or already in use.

sixauth.main

The sixauth.main module provides all of the functionallity of the sixauth module, and then some. The AuthSesh class is basically just a wrapper for all the functions in this module. If you wish to use any of the raw functions in this module, it is recomended that you already have a very strong understanding of authentication, databases, and all the jazz. I tried my best to explain what happens in the comments of each of the functions, you can read them here.

Hosting a Server

This module provides a very basic python server for AuthSesh instances to connect to. You can start it with the server() function:

from sixauth.main import server server("0.0.0.0", 5678)

This will start a server in the console on port 5678 and will look for all incoming ip addresses. There are also a few keyword debug booleans, debug and log_senseitive_info. The keyword option, cache_threshold, sets how long, in seconds, a user has to be inactive on the server before their cache position is deleted.

License and Disclaimer

The sixauth library is licensed under the MIT License, which means it is free to use and distribute for both personal and commercial purposes. The documentation for the library has been generated by an AI trained by OpenAI, and may not be entirely accurate or up-to-date. It is recommended to consult the source code of the library for the most accurate information.

Authors

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

sixauth-1.0.2.tar.gz (17.4 kB view hashes)

Uploaded Source

Built Distribution

sixauth-1.0.2-py3-none-any.whl (14.5 kB view hashes)

Uploaded Python 3

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