Skip to main content

This Python module securely validates and extracts user data from a URL-encoded string, using HMAC and SHA-256 for data integrity. It features a User class to structure user information and a Data class for validation and data parsing. Ideal for web applications needing secure user authentication and data management, it's easy to integrate and use.

Project description

Data Validation and User Extraction Module

This Python module is designed to handle the validation and extraction of user data from a URL-encoded string. It uses HMAC and SHA-256 hashing to ensure data integrity and security. The module provides a simple way to validate input data and parse it into a structured User object.

Requirements

This module requires Python 3.6+ and uses the following standard libraries:

  • hmac
  • hashlib
  • urllib
  • json
  • dataclasses

Installation

No external libraries are required for this module. Simply include the code in your Python project.

Usage

User Class

The User class is a data class that holds the following information about a user:

  • id: The user's unique identifier (integer).
  • first_name: The user's first name (string).
  • last_name: The user's last name (string).
  • username: The user's username (string).
  • language_code: The language code of the user (string).
  • is_premium: A boolean indicating if the user has a premium account.
  • allows_write_to_pm: A boolean indicating if the user allows writing to private messages.

Data Class

The Data class is responsible for validating input data and extracting user information from a URL-encoded string.

Initialization

To create an instance of the Data class, you need to provide a bot token:

data_instance = Data(BOT_TOKEN="your_bot_token_here")

is_valid_data Method

This method checks if the provided data is valid by comparing the generated hash with the initial data hash.

is_valid = data_instance.is_valid_data(INIT_DATA_HASH="your_init_data_hash", DATA_CHECK_STRING="your_data_check_string")

GetData Method

This static method extracts user data from the data check string and returns a User object.

user = Data.GetData(DATA_CHECK_STRING="your_data_check_string")

Example

Here's an example of how to use the module:

BOT_TOKEN = "1231212:sdsadasdsadasd231ec"
INIT_DATA_HASH = "90677c2f2e1326cdb4d5cd781905c375f5397b8f6dbee501487385aa3faf3e0e"
DATA_CHECK_STRING = "auth_date=1721578504&chat_instance=-5432073769796079823&chat_type=private&user=%7B%22id%22%3A6195030789%2C%22first_name%22%3A%22._.%22%2C%22last_name%22%3A%22%22%2C%22username%22%3A%22ksdaskdnc2w%22%2C%22language_code%22%3A%22en%22%2C%22allows_write_to_pm%22%3Atrue%7D"

data_instance = Data(BOT_TOKEN)
if data_instance.is_valid_data(INIT_DATA_HASH, DATA_CHECK_STRING):
    user = Data.GetData(DATA_CHECK_STRING)
    print(f"User {user.first_name} ({user.username}) is authenticated.")
else:
    print("Invalid data provided.")

License

This module is licensed under the MIT License. Feel free to use and modify it as needed.

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

verifytelegram-0.1.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

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

verifyTelegram-0.1.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file verifytelegram-0.1.0.tar.gz.

File metadata

  • Download URL: verifytelegram-0.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for verifytelegram-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1bacc60e590474951084e890f411b622930ae426a1fa75b9eb82d98ed4eaa6ad
MD5 8df5e5867e1f3655de1a0d057b5373a7
BLAKE2b-256 24f1f1ca13a1f85de2b9e6166915a3a93e58a47865531057aee37b190a66eb80

See more details on using hashes here.

File details

Details for the file verifyTelegram-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: verifyTelegram-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.5

File hashes

Hashes for verifyTelegram-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a0ef9a5b46a12f7d512b09ee4a1e24caf58f326b0a643c400fc5e106908edf7d
MD5 9f6e1659a66c27b11b893610ef916154
BLAKE2b-256 e1be22b0884fd304fdaed264dac813fa61b0f9267bde8d2a9e9f0280d13d25ec

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