Ask Documentation
WebsiteGitHubPyPI
  • Introduction
  • Getting Started
    • Install & Get Started
    • Hello, World!
  • Routes & Requests
    • Routes
    • Defining Routes
    • Request Data
    • HTTP Status Codes & Methods
    • CORS
  • Response
    • JSON Response
    • JSON Response With an HTTP Status Code
  • Classes
    • Class Instance Variable
    • Initialization/Constructor Method
  • Data Types
    • Dictionaries
  • Built-in Utilities
    • Quick_set()
    • Deep()
    • Serialize()
    • Require_keys()
    • Random Generators
    • Pattern Matching
    • Email
  • Database
    • Ask and Databases
    • Models/Classes
      • Columns
      • Initialization/Constructor
      • Serialization
      • The &basic decorator
    • CRUD
      • Add
      • Select
      • Update
      • Delete
    • Check if a Row Exists
    • Sorting
    • Database Lists
  • JWT Authentication
    • Introduction
    • Protecting Routes
    • How to Create a Basic Login System
    • Properties & Methods of _auth
    • Making Requests to Protected Routes
  • Decorators
    • What are Decorators?
    • Create and Use Custom Decorators
    • Built-in Decorators
  • Security
    • Hashing
    • Route Security
    • Environment Variables
  • Configuring the Transpiler
  • Askfile.toml
  • Modules & Libraries
    • Importing an Ask Module
    • Includes
    • Importing Python Modules
  • Development Tools
    • Editor Syntax Highlighting
    • Automatic API documentation
    • CLI Flags
    • Running in development mode
    • Versioning System
  • Contribute
    • Feature Requests
    • Bug Reports
    • Contribute Code
Powered by GitBook
On this page
  • hash()
  • Usage
  • Parameters:
  • check()
  • Usage
  • Parameters:
Export as PDF
  1. Security

Hashing

Hash sensitive information like passwords and email addresses.

Hashing is the practise of converting data into another format to secure or hide it. Hashing is done by hashing algorithms that are mathematically designed to be one-way, meaning it’s hard to decode back to the original format without some sort of key for example.

Ask’s built-in hashing solution uses sha256 encryption. SHA256 turns a given string into a 256 character long string.

Use the hash object for this.

hash()

Returns the given value enypted by the SHA256 algorithm.

Usage

hash.hash([value])

Parameters:

  • Typically a string.

check()

Check if a value corresponds with a hash. Used for e.g. verifying passwords. Returns True/False.

Usage

hash.check([hash], [value])

Parameters:

  • A SHA256 encrypted value.

  • The value to compare.

  • This will e.g. be the user-submitted plain text password your verifying with the one stored in the database that has been hashed.

This function only helps you save a bit of typing. Technically you could just do:

if hash_string == hash.hash(’not hashed’):
    # True
    ...
else:
    # False
    ...

But using .check is a bit easier to both read and write.

PreviousBuilt-in DecoratorsNextRoute Security

Last updated 4 years ago