Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New get_hash() Function #1

Merged
merged 5 commits into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ALLFUNCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,5 @@ Generates a UUID using version 4 by default but you can choose.

## external_verbose_output() by @hamdivazim
If you are printing a lot of data, you can use this method to write the output to log file.
## get_hash() by @MKM12345
This takes a string as input, hashes it using the SHA-256 algorithm, and returns the hexadecimal representation of the hash value.
8 changes: 7 additions & 1 deletion usefulib/_usefulibs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import string # generate_random_string()
import uuid # generateUUID()
import os # external_verbose_output()
import hashlib # get_hash()

""""""

Expand Down Expand Up @@ -133,4 +134,9 @@ def external_verbose_output(data, path="data.log"):

with open(path, "w") as f:
f.write("# Logged by usefulibs.external_verbose_output()\n\n")
f.write(data)
f.write(data)
def get_hash(string):
"""
@MKM12345 - This function takes a string as input, hashes it using the SHA-256 algorithm, and returns the hexadecimal representation of the hash value. Useful for developers that one to store strings without actually having to store them.
"""
return hashlib.sha256(string.encode('utf-8')).hexdigest()
12 changes: 11 additions & 1 deletion usefulib/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"""

import unittest
import _usefulibs
from _usefulibs import *

class TestUsefulibs(unittest.TestCase):
Expand Down Expand Up @@ -73,7 +74,16 @@ def test_external_verbose_output(self):

with open(R"usefulib\temp_data\ext_verbose_test.log", "r") as f:
self.assertEqual(f.read(), "# Logged by usefulibs.external_verbose_output()\n\nTest Data\n1 2 3\na b c")
def test_get_hash(self):
""" @MKM12345 """
password = "myPassword123"
password_hash = get_hash(password)
user_input = input("Please enter your password: ")
if get_hash(user_input) == password_hash:
print("Welcome!")
else:
print("Incorrect password")


if __name__ == "__main__":
unittest.main()
unittest.main()