Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 923241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:09:39+00:00 2026-05-15T19:09:39+00:00

I am looking to generate passwords using strings typed by the user, the book

  • 0

I am looking to generate passwords using strings typed by the user, the book I am reading recommends using sha over md5 because it is considered stronger.

sha however has been deprecated and I am now using the hashlib module to encrypt me strings in a similar way to that shown here: http://docs.python.org/py3k/library/hashlib.html#module-hashlib.

import os
import hashlib
from getpass import getpass

print('Username: ' + os.environ['USER'])
passwd = getpass('Password: ')
h = hashlib.md5()
h.update(passwd.encode())
passwd_encrypt = h.hexdigest()

I am then comparing passwd_encrypt with a plain ascii file containing a list of usernames and encrypted passwords like so:

THO     5f4dcc3b5aa765d61d8327deb882cf99

Is this a suitable technique for encryption of the password or is there a better way? I am also interested in whether storing the passwords in this way is suitable and what the alternatives may be.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:09:39+00:00Added an answer on May 15, 2026 at 7:09 pm

    There is no “sha” algorithm. The sha1 algorithm is much stronger than md5, since md5 is completely broken. I believe there is an algorithm that takes microseconds to generate a collision.

    Sha1 has been considerably weakened by cryptanalysts, and the search is on for the next big thing, but it is still currently suitable for all but the most paranoid.

    With regard to their use in passwords, the purpose is to prevent discovery of the original password. So it doesn’t really matter much that md5 collisions are trivial to generate, since a collision simply yields an alternate password that has the same md5 hash as the original password, it doesn’t reveal the original password.

    Important note:

    Your version is missing an important component: the salt. This is a random string that is concatenated to the original password in order to generate the hash, and then concatenated to the hash itself for storage. The purpose is to ensure that users with the same password don’t end up with the same stored hash.

    import random
    
    print('Username: ' + os.environ['USER'])
    passwd = getpass('Password: ')
    salt = ''.join(random.choice('BCDFGHJKLMNPQRSTVWXYZ') for range(4))
    h = hashlib.md5()
    h.update(salt)
    h.update(passwd.encode())
    passwd_encrypt = salt + h.hexdigest()
    

    You then verify the password by reusing the stored salt:

    passwd = getpass('Password: ')
    salt = passwd_encrypt[:4]
    h = hashlib.md5()
    h.update(salt)
    h.update(passwd.encode())
    if passwd_encrypt != salt + h.hexdigest():
        raise LoginFailed()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a tool/framework to (automatically) generate a Swing user interface to
I'm looking to generate a random number and issue it to a table in
I'm looking for a tool which can generate a Makefile for a C/C++ project
I'm looking for a framework to generate Java source files. Something like the following
I'm looking for a way to generate a set of random sided, but regular,
I'm looking for an algorithm to generate permutations of a set in such a
I'm looking for a tool that will generate an assembly/project dependency diagram in Visio
I've been looking for a simple Java algorithm to generate a pseudo-random alpha-numeric string.
I am looking for database-caching framework for C++ providing the following: Generate object/table representations
I'm looking for Java code that can be used to generate sound at runtime

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.