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

New get_hash() Function #1

merged 5 commits into from
Apr 23, 2023

Conversation

MKM12345
Copy link
Contributor

@MKM12345 MKM12345 commented Apr 21, 2023

What's in this usefulib?

The get_hash() function is used to calculate the SHA-256 hash of a given string. It takes a string as an argument, puts it in UTF-8 format, and then uses the hashlib library in Python to compute the SHA-256 hash of the encoded string. Finally, it returns the hexadecimal representation of the hash.

Did you add tests?

I was able to put my function in test.py.

Does this solve an issue?

No, just adds a new function

Checklist

@MKM12345
Copy link
Contributor Author

Also تَقَبَّلَ اللهُ مِنَّا وَمِنكُم

@MKM12345
Copy link
Contributor Author

An example of usage is this:

from _usefulib.py import get_hash

input_password = "password123" # user's input password during login
stored_hash = get_hash(input_password) # hash of the password stored in the system

user_input = input("Enter a password: ")
hashed_input = get_hash(user_input)

if hashed_input == stored_hash:
    print("Correct")
else:
    print("Wrong")

@hamdivazim
Copy link
Owner

Is the hashlib library installed using pip?

@MKM12345
Copy link
Contributor Author

Is the hashlib library installed using pip?

Hashlib has been part of the standard library since python2. 5, released in 2006. You don't need to install it from pypi.

@hamdivazim
Copy link
Owner

Also before I merge could you move the import hashlib in test.py into the setUp method. Thanks for this PR!

@MKM12345
Copy link
Contributor Author

Also before I merge could you move the import hashlib in test.py into the setUp method. Thanks for this PR!

I have?

@MKM12345
Copy link
Contributor Author

Also before I merge could you move the import hashlib in test.py into the setUp method. Thanks for this PR!

Also your welcome

@hamdivazim
Copy link
Owner

There is an empty method in the class called setUp() if you could remove the comment and replace that with the import that would be great

@MKM12345
Copy link
Contributor Author

Also before I merge could you move the import hashlib in test.py into the setUp method. Thanks for this PR!

I have?

Oh sorry. Will do when I’m free

@MKM12345
Copy link
Contributor Author

There is an empty method in the class called setUp() if you could remove the comment and replace that with the import that would be great

Sure, I will do later

@hamdivazim
Copy link
Owner

Alright awesome, will merge when the change is done. Thanks again :)

@MKM12345
Copy link
Contributor Author

Alright awesome, will merge when the change is done. Thanks again :)

I have been honoured to contribute to a open-source to a Python library. I will ensure the change is done. Thanks and your welcome.

@hamdivazim
Copy link
Owner

Will you do the change or would you like me to do it? I can commit them to this fork.

@MKM12345
Copy link
Contributor Author

MKM12345 commented Apr 23, 2023

No, but thanks any way. I was experiencing some problems when trying to do the change, so I just changed the test_get_hash(). This PR is ready for merging unless you have anything else to say.

@hamdivazim
Copy link
Owner

Oh, the tests were fine, please do use assertEqual. If you would like, I can rewrite the tests for you - try not to use print in tests. Before I merge, could you confirm whether you would want me to do that, or would you like to fix them yourself?

@MKM12345
Copy link
Contributor Author

Thanks - that will be helpful. I'm a little busy so appreciate it.

@hamdivazim
Copy link
Owner

Alright cool - thanks for the PR! Also, could you open discussions on this repository with any questions you have?

@MKM12345
Copy link
Contributor Author

MKM12345 commented Apr 23, 2023

If I do - I'll see if I can.

Alright cool - thanks for the PR! Also, could you open discussions on this repository with any questions you have?

You are very welcome.

@hamdivazim hamdivazim merged commit a7cb6c8 into hamdivazim:main Apr 23, 2023
@hamdivazim hamdivazim self-assigned this Apr 23, 2023
@hamdivazim
Copy link
Owner

Also @MKM12345, your get_hash() usefulib does not catch the error if a string is not inputted. I have added that in for you (this is an example for a good test).

hamdivazim added a commit that referenced this pull request Apr 23, 2023
@MKM12345
Copy link
Contributor Author

Also @MKM12345, your get_hash() usefulib does not catch the error if a string is not inputted. I have added that in for you (this is an example for a good test).

Thanks @hamdivazim for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants