LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-17-2009, 02:52 PM   #1
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Rep: Reputation: 51
sha module is deprecated; use the hashlib module


hi

I've upgrade my Ubuntu to karmic and have this python script to protect the start of thunderbird using password:
Code:
#!/usr/bin/python

# Password protector
import os, sys, sha, getpass

# Read in hash
hash_file = open("/home/ania/.password_protect", "r")
hash = hash_file.read()

# Get new hash
pwhash = ''
counter = 0
while pwhash != hash:
    pwhash = sha.sha(getpass.getpass("Password: ")).hexdigest()
    counter += 1
    if counter > 3:
        sys.exit()

os.system("/usr/bin/thunderbird")
but I'm getting this error message:
Code:
 
/home/pass.py:4: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import os, sys, sha, getpass
howto solve this problem?

Last edited by cccc; 07-17-2009 at 03:04 PM.
 
Old 07-17-2009, 04:55 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by cccc View Post
hi

I've upgrade my Ubuntu to karmic and have this python script to protect the start of thunderbird using password:
Code:
#!/usr/bin/python

# Password protector
import os, sys, sha, getpass

# Read in hash
hash_file = open("/home/ania/.password_protect", "r")
hash = hash_file.read()

# Get new hash
pwhash = ''
counter = 0
while pwhash != hash:
    pwhash = sha.sha(getpass.getpass("Password: ")).hexdigest()
    counter += 1
    if counter > 3:
        sys.exit()

os.system("/usr/bin/thunderbird")
but I'm getting this error message:
Code:
 
/home/pass.py:4: DeprecationWarning: the sha module is deprecated; use the hashlib module instead
  import os, sys, sha, getpass
howto solve this problem?
To follow the suggestion ?
 
Old 07-17-2009, 07:38 PM   #3
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
howto install hashlib module and change this script to ask for a password without errors?

Last edited by cccc; 07-17-2009 at 07:45 PM.
 
Old 07-17-2009, 10:40 PM   #4
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by cccc View Post
howto install hashlib module and change this script to ask for a password without errors?
hashlib is part of Python's standard library. All you have to do is replace "sha.sha" with "hashlib.sha1", and change the import accordingly.
 
Old 07-18-2009, 10:57 AM   #5
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by Dan04 View Post
hashlib is part of Python's standard library. All you have to do is replace "sha.sha" with "hashlib.sha1", and change the import accordingly.
Seriously speaking, I think SHA1 is deprecated because of insufficient cryptographic strength.

So, say, SHA256.
 
Old 07-18-2009, 12:57 PM   #6
cccc
Senior Member
 
Registered: Sep 2003
Distribution: Debian Squeeze / Wheezy
Posts: 1,623

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by Dan04 View Post
hashlib is part of Python's standard library. All you have to do is replace "sha.sha" with "hashlib.sha1", and change the import accordingly.
thx a lot, I changed the script and now it works well without warnings:
Code:
#!/usr/bin/python

# Password protector
import os, sys, hashlib, getpass

# Read in hash
hash_file = open("/home/ania/.password_protect", "r")
hash = hash_file.read()

# Get new hash
pwhash = ''
counter = 0
while pwhash != hash:
    pwhash = hashlib.sha1(getpass.getpass("Password: ")).hexdigest()
    counter += 1
    if counter > 3:
        sys.exit()

os.system("/usr/bin/thunderbird")

Last edited by cccc; 07-18-2009 at 01:17 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rtl8187 driver module load error (Invalid module format) j_75080 Linux - Networking 3 07-06-2009 09:37 PM
cpan2tgz error on installing module: Failed to find module: build_requires pwc101 Slackware 6 01-08-2009 05:24 AM
error: -1 Invalid module format when using insmod with module cross-compiled for arm AndrewShanks Linux - Embedded & Single-board computer 4 10-15-2007 03:50 AM
kcmshell module, Background&Screensaver Module can't be launch (but works @LookNFeeL) bobbyjoe Linux - Software 0 01-08-2005 04:48 AM
'Invalid module format' loading simple module on Suse Linux Professional 9.1 rocketdude Linux - Distributions 3 07-27-2004 11:40 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration