Skip to main content

pws256: A module that is used for users and passwords, and also has validation methods to check passwords with strings

Project description

pws256

This is a python module for username and passwords with hash functions, which you can customise.

Example

>>> import pws256
>>> pw = pws256.Password("password")
>>> pw.verify("password")
True
>>> pw.verify("pasword")
False
>>> pw.hsh_func
<built-in function openssl_sha256>
>>> pw2 = pws256.Password(
...    raw = "password",
...    hsh_func = lambda x : "".join(reversed(x)),
...    hsh_enter = str,
...    hsh_after = None
...)
...
>>> pw2.verify("password")
True
>>> pw2.hashed # Includes salt so when reversed, salt is at the back
"drowssap...bv4w75..."
>>> import pws256.users as u
>>> pw3 = pws256.Password("hello")
>>> usr = u.User("me", pw3)
>>> usr.save_to_file("test.csv")
>>> user = u.User.load_from_file("me", "test.csv")
>>> user.password.verify("hello")
True
>>> pw4 = pws256.defaultpass("hello")
>>> pw4.salt = "abc"
Traceback (most recent call last):
...
>>> pw4.salt_settable(True)
>>> pw4.salt = "abc"
>>> pw4.salt
"abc"
>>> pw4.salt_settable(False)
Traceback (most recent call last):
...
>>>

pws256.Password()

Normal pws256.Password()

pw = pws256.Password(
    raw: str
)

Creates a password that can be verified and shaped in different ways

Custom pws256.Password()

pw = pws256.Password(
    raw: str,
    hsh_func: function | class = hashlib.sha256,
    hsh_enter: type[str] | type[bytes] = type[bytes],
    hsh_after: str = ".hexdigest()"
)

Create a Password with a custom function that is called, type that goes into that function, and what comes after e.g. .hexdigest()

Initialisation Parameters

hsh_func

hsh_func is a parameter that must be a function.
If you had a function called reverse and it took the reverse of a string,
to use it here, you would have to have your function as the hsh_func

hsh_enter

hsh_enter determines which type the raw string should be before it enters the hash function
hsh_enter is default as bytes, but if your function took in a string, you should change it to str

hsh_after

hsh_after detirmines what to put after the function call using eval()
for example, if you had hashlib.sha256 as your hsh_func, you should have
".hexdigest()" as your hsh_after. If you don't want to call a method after,
put hsh_after as None

Methods

validate()

The validate method validates the password against a string

pw = pws256.Password("hello")
pw.validate("hello") # returns True
pw.validate("bello") # returns False

pws256.defaultpass()

Derived from Password and has no parameters to confuse you!

pw = pws256.defaultpass(
    raw: str
)

pws256.users.User()

usr = users.User("username", pws256.Password(...))

You can create a user with users.User()
The password parameter has to be a pws256.Password() or has to be
derived from pws256._Password().

Initialisation Parameters

username

A custom username that must be a string.

password

A password that is a class derived from _Password()
If the class is not, it will throw an error.

Methods

save_to_file(filename: str | TextIOWrapper, close: bool)

You can save it to a file by using this method. The close param
at the end can be used if you want to close the file afterwards.

(classmethod) load_from_file(username: str, filename: str | TextIOWrapper, ...)

users.User.load_from_file("username", "doc.csv")

You can use this method to get a new User from a file using a username If you had a user who's username was "username", you could get it out from
doc.csv using this method.

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

pws256-1.1.14.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pws256-1.1.14-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file pws256-1.1.14.tar.gz.

File metadata

  • Download URL: pws256-1.1.14.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pws256-1.1.14.tar.gz
Algorithm Hash digest
SHA256 64aa10b145118b09cbb9b6befa13d78aae07f7c3ac0b6ad2918c3ce32ebb44e5
MD5 f45afb106196c42320c188290f9e71f3
BLAKE2b-256 ffa8500b971b39d9ef14d5fc429c65940f88d60e76ce40f25248aa8b7f14ef61

See more details on using hashes here.

File details

Details for the file pws256-1.1.14-py3-none-any.whl.

File metadata

  • Download URL: pws256-1.1.14-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.9

File hashes

Hashes for pws256-1.1.14-py3-none-any.whl
Algorithm Hash digest
SHA256 771268f29900e6cfe50601e5b51b64afc2906f6625f2322a6d04481738853575
MD5 01234098f67f5d615ddc30b208e321be
BLAKE2b-256 3a2381a37e71efc7c5b730e8dccb9f6951647569c63555f639df440c875df215

See more details on using hashes here.

Supported by

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