Python Forum
How to compare in python an input value with an hashed value in mysql table?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to compare in python an input value with an hashed value in mysql table?
#4
If you have the license key in the DB why would you need to compare the hash, not the key itself?
Are you sure it's a hash of the key? It doesn't make sense to keep both the license key and it's hash in the DB.
Also hash may be hash of concatenation of several fields -e.g. license key + activation date + expiration date (just an example), so without knowing the hash function and what is hashed exactly it's difficult to calculate the hash

As to the passwords - it's not that simple question at all if it has to be done right
Maybe read https://crackstation.net/hashing-security.htm from gentle introduction
for example:
from hashlib import md5, sha256, sha512
key = 'def50200352f5dc4bd8181a9daebbf4f9177fe725111a5a479d64636d01c2a10074e0c645abe898dea18210af563a5334288420551ab61c18ca4506cd03aa5d2bdd40933ddf7ca4d4b61b1c0f58a3830cbe0891cf4ff526311d5d637a55a574eca2c3a1b487b56'

for hash_func in (md5, sha256, sha512):
    print(hash_func(key.encode()).hexdigest())
Output:
e39f98acdcd52c6a5804d4f58f6a5219 d44607349c1d7d99d827cb58930883f800c54b0aa3b631179cb455ef05df808e eed729e73dbcfc8ca05547a3e0c557b54d4051b823cb84a4a904505d6b57bbe5a3eae47f030f5b71342870d81ba1a5a18dd525b4b3a341d8bb7b38a1ce264768
that's the output of the md5, sha256 and sha512 hash functions applied on license key. Probably the hash function is sha256, but applied on something different from license key
Looking at the source code - there is file
license-manager-for-woocommerce.zip\license-manager-for-woocommerce\includes\Crypto.php
they use sha256, but if I get it right they apply it on some encrypted string.
Encryption is done using https://github.com/defuse/php-encryption which is in
license-manager-for-woocommerce.zip\license-manager-for-woocommerce\vendor\defuse\php-encryption\docs
There is extensive documentation for that library.
Given the above I don't want to dive further into this plugin. There is API for the plugin, whay don't you use it for your needs (e.g. validate a key)?
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
RE: How to compare in python an input value with an hashed value in mysql table? - by buran - Jan-14-2020, 10:01 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Mysql and mysql.connector error lostintime 2 683 Oct-03-2023, 10:25 PM
Last Post: lostintime
  Mysql Workbench table not updated CatBall 2 1,111 Feb-13-2023, 05:37 PM
Last Post: CatBall
Photo How to select NULL and blank values from MySQL table into csv python300 9 2,445 Dec-27-2022, 09:43 PM
Last Post: deanhystad
  Mysql error message: Lost connection to MySQL server during query tomtom 6 16,089 Feb-09-2022, 09:55 AM
Last Post: ibreeden
Question Debian 11 Bullseye | Python 3.9.x | pip install mysql-connector-python-rf problems BrandonKastning 4 6,690 Feb-05-2022, 08:25 PM
Last Post: BrandonKastning
  Compare two Excel sheets with Python and list diffenrences dmkfon 1 14,656 Oct-09-2021, 03:30 PM
Last Post: Larz60+
  SaltStack: MySQL returner save less data into Database table columns xtc14 2 2,168 Jul-02-2021, 02:19 PM
Last Post: xtc14
  Python and MySql ogautier 8 3,367 May-20-2021, 11:10 PM
Last Post: Pedroski55
  Python and MySQL Pedroski55 5 3,245 Mar-23-2021, 06:40 AM
Last Post: ndc85430
  "'DataFrame' objects are mutable, thus they cannot be hashed" Mark17 1 6,832 Dec-25-2020, 02:31 AM
Last Post: tinh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020