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 8361443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:42:08+00:00 2026-06-09T11:42:08+00:00

Using: Python 3.2.3, scrypt 0.5.5 module, Ubuntu 12.04 I installed the scrypt module fine.

  • 0

Using: Python 3.2.3, scrypt 0.5.5 module, Ubuntu 12.04

I installed the scrypt module fine. I ran the sample code on the page fine. I also found an expanded version of the sample code, which did fine too. But I wanted to test if it would hash the same word twice, so I added a section call to Encrypt(), to simulate the concept of hashing it once for the DB and then hashing again when a user logs in, so my full code looks like this:

import random,scrypt

class Encrypt(object):

    def __init__(self):
        pass

    def randSTR(self,length):
        return ''.join(chr(random.randint(0,255)) for i in range(length))

    def hashPWD(self,pwd, maxtime=0.5, datalength=64):
        return scrypt.encrypt(self.randSTR(datalength), pwd, maxtime=maxtime)

    def verifyPWD(self,hashed_password, guessed_password, maxtime=0.5):
        try:
            scrypt.decrypt(hashed_password, guessed_password, maxtime)
            return True
        except scrypt.error:
            return False

if __name__ == '__main__':
    e = Encrypt()
    user_pw = 'theansweris42'
    user_salt = 't9'
    pw_salt = user_pw + user_salt
    hashed_pw = e.hashPWD(pw_salt) # To be stored len()==192
    y = e.verifyPWD(hashed_pw, pw_salt)              # True
    n = e.verifyPWD(hashed_pw, 'guessing'+ pw_salt)  # False
    print(y)
    print(n)
    #print("Hash: %s" % (hashed_pw))

    x = Encrypt()
    user_pw2 = 'theansweris42'
    user_salt2 = 't9'
    pw_salt2 = user_pw2 + user_salt2
    hashed_pw2 = x.hashPWD(pw_salt2) # To be stored len()==192
    y2 = x.verifyPWD(hashed_pw, hashed_pw2)              # True
    print(y2)
    print(pw_salt)
    print(pw_salt2)
    print(hashed_pw)
    print(hashed_pw2)

…as you can see, I also hard coded the salt (for testing). Strangely, everytime I run this, the hashed_pw & hashed_pw2 are always different. Why is this hashing the same password differently each time? Shouldn’t it be outputting the same hash each time I give it the exact same input? I’ve been trying to figure this out for an hour, so I figure I better ask.

  • 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-06-09T11:42:10+00:00Added an answer on June 9, 2026 at 11:42 am

    You encrypt two different random strings with the same password (plus a salt). This will result in two different outputs.

    The trick used here is that the password + salt can be used to decrypt that random string, while the incorrect password will raise an error. Hence, you don’t need to store the original random string to make sure that the password was correct, and since the string used was random (within the limits of the random number generator) it’s going to be extremely hard to crack the password.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was using ubuntu. I found that many Python libraries installed went in both
I'm currently using the toprettyxml() function of the xml.dom module in a Python script
I'm getting the following error when using the multiprocessing module within a python daemon
I am using a python script to do my webserver using the BaseHTTPServer module.
I am accessing a python script using jython and apparently the _winreg module is
I'm using PyKml module in order to form kml inside my Python script. I
From within a python script (main.py), I am using the subprocess module to run
Using: Ubuntu 11.04 Django 1.3 Python 2.7 Following the tutorial at Writing your first
I am using python twisted module to intercept headers. I have the following script:
I m trying to automate logging into a website using Python's mechanize module.Following is

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.