# # Frontend side # import hashlib urs_id = '10101010101010101010' salt = 'this-1s-a-secr3t!!' user_hash = hashlib.sha256(urs_id + salt) # The hash would be included as a hidden input field in the form. print('Hidden input field value:') print(user_hash.hexdigest()) # # API side receiving form POST request # hash_input_data = '855c4e492b00f8404a638e970a1be5fa43705d779c8c6e6b03fae0eabd6f446a' urs_id = '10101010101010101010' salt = 'this-1s-a-secr3t!!' user_hash = hashlib.sha256(urs_id + salt) # The hash would be included as a hidden input field in the form. print('Hash checking') print('Request hash:') print(hash_input_data) print('API side hash:') print(user_hash.hexdigest()) print('Allow request: ' + str(user_hash.hexdigest() == hash_input_data))
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question