Skip to main content

Account credentials checker

This package takes care of verifing the credentials serverside.

Download

You can pip install by

pip3 install Credentials-Validator

Usage

You can import the pakage by typing

from Credentials_Validator import UsernameValidator, PasswordValidator


The general usage is:

from Credentials_Validator import UsernameValidator

user = UsernameValidator([4], # length range
                         [1], # number of lower-case chars range
                         [1], # number of upper-case chars range
                         [1,3], # number of numbers range
                         [0,0], # number of symbols range
                         )


The use of range is:

[2, 5] # minimum 2, maximum 5 characters
[1] # at least one
[0] # not necessary, not denied
[0, 4] # not necessary, maximum 4 characters
[0, 0] # denied

Validation

In order to validate a text (Username or password) you have to call the method Validator.verify(text).
It returns two objects:

  1. a boolean (True if the text is valid, False if there is one or more errors)
  2. a string, that can be:
    • '' empty, if there are no errors
    • 'length' if the text is too short or too long
    • 'lower' if there are too few or too many lower-case characters
    • 'upper' if there are too few or too many upper-case characters
    • 'digit' if there are too few or too many numbers
    • 'symbols' if there are too few or too many allowed symbols
from Credentials_Validator import UsernameValidator

user = UsernameValidator([4, 10], [1], [2], [0], [1],)

is_valid, error = user.verify('PasswOrd!')
print((is_valid, error))
#returns (True, '')

is_valid, error = user.verify('PasswOrd3')
print((is_valid, error))
#returns (False, 'symbols')

is_valid, error = user.verify('Password!')
print((is_valid, error))
#returns (False, 'upper')

is_valid, error = user.verify('th1sPasswOrdist00long')
print((is_valid, error))
#returns (False, 'length')

Differences between UsernameValidator and PasswordValidator

UsernameValidator

The UsernameValidator comes with a special argument called django_model.
It can be used to automatically check if the username is already taken in the Django User model, if it is taken, it will return the error 'existing'
In this example the default User model is passed:

from django.contrib.auth.models import User
from Credentials_Validator import UsernameValidator

user = UsernameValidator([4,10], [1], [1], [2], [0,0], django_model=User)

If you are using a custom Django User model:

from django.contrib.auth import get_user_model
from Credentials_Validator import UsernameValidator

user = UsernameValidator([4,10], [1], [1], [2], [0,0], django_model=get_user_model())

PasswordValidator

The PasswordValidator comes with a special argument called username.
It checks if the password is the same as the username, in which case it returns the 'equal' error.\

from Credentials_Validator import PasswordValidator

username = 'myusername'

password = PasswordValidator([8,12], [2], [2], [2], [1], username=username)

Extra features

Customization


The default symbols are: !"#$%&'()*+,-./:;<=>?@[\]^_{|}~.

You can customize the simbols by passing your custom list (string) as a keyword argument:

from Credentials_Validator import UsernameValidator

my_symbols = '!?$%&@#'

user = UsernameValidator([4, 10], [1], [1], [0], [1], symbols_list=my_symbols)

Inheritance

You can add your custom verification function by inheriting the Validator class and overriding the __init__ method to add keyword arguments and extra_validation one to add your validatin function.
The __init__ should look like this:

from Credentials_Validator import Validator

class MyValidator(Validator):

    def __init__(self, length, chars, Chars, nums, symbols, **kwargs):
        super().__init__(length, chars, Chars, nums, symbols, **kwargs) # DON'T EDIT THIS!

        self.myargument = kwargs.get('mykeyword', None) # Edit 'myargument' and 'mykeyword'

The extra_validation should return None if the text is valid, if it is not, False and myerrormessage (can be anything)

    def extra_validation(self, text): # text is the .verify() argument
        if self.myargument in text: # can be any condition
            return False, 'myerror'
        return None

Metadata

Release files for Credentials-Validator 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Credentials-Validator 0.0.4
File Size Uploaded Provenance Actions
Credentials_Validator-0.0.4.tar.gz 3.9 kB Without provenance Details for Credentials_Validator-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for Credentials-Validator 0.0.4
File Interpreter ABI Platform Actions
Credentials_Validator-0.0.4-py3-none-any.whl Python 3 none any Details for Credentials_Validator-0.0.4-py3-none-any.whl

Total release size: 9.4 kB

Release files / Credentials_Validator-0.0.4.tar.gz

Download URL Credentials_Validator-0.0.4.tar.gz
Size 3.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b94436c823f93ba3fabb8d20c465314fc5742bc8564f0431654f88713efb8703
BLAKE2b-256 checksum
How to use checksums
e7f6558a82787dc6d856cc4dd41ce852580b8c53370790c010db4b5f82d267f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

Release files / Credentials_Validator-0.0.4-py3-none-any.whl

Download URL Credentials_Validator-0.0.4-py3-none-any.whl
Size 5.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cd87b5c99f8c6af8ee094353080f80655e292b6e541047f5bda5206083489ca9
BLAKE2b-256 checksum
How to use checksums
0f11c3267787a74db75fbf5808eb3fdefdb40dc321d6537ebd816a0bd36d781f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.14.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.7.3

Security for Credentials-Validator 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page