Page 2 of 2 FirstFirst 12
Results 11 to 15 of 15

Thread: Python function to encrypt and decrypt password

  1. #11
    Join Date
    Oct 2005
    Location
    Belgium
    Beans
    78
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Python function to encrypt and decrypt password

    Quote Originally Posted by Wybiral View Post
    Do you really need to decrypt it, or can you just encrypt the password that the user enters and check that with the previously encrypted password (in the file). This is how almost all password systems work.
    the password is used for checking gmail, pop3 and imap accounts so i really need to decrypt it (i can not send the encrypted password for login)

  2. #12
    Join Date
    Mar 2006
    Location
    Ireland
    Beans
    42
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: Python function to encrypt and decrypt password

    A lot of programs simply use base-64 encoding to mask passwords like this. It's low security, only for making them not human readable. In python, you can use the base64 module: http://docs.python.org/lib/module-base64.html The relevant functions are b64encode(s) and b64decode(s).

    If you're writing a gnome app however, a better option might be to use the gnome keyring. If you want to take this approach, this page might help: http://www.rittau.org/blog/20070726-01

    -Kevin

  3. #13
    Join Date
    Oct 2005
    Location
    Belgium
    Beans
    78
    Distro
    Ubuntu 8.10 Intrepid Ibex

    Re: Python function to encrypt and decrypt password

    Quote Originally Posted by kevykev View Post
    A lot of programs simply use base-64 encoding to mask passwords like this. It's low security, only for making them not human readable. In python, you can use the base64 module: http://docs.python.org/lib/module-base64.html The relevant functions are b64encode(s) and b64decode(s).
    This was exactly what i needed! simple but it works and scares away normal users

    Thank you all for your replies!

  4. #14
    Join Date
    Dec 2008
    Beans
    2

    Re: Python function to encrypt and decrypt password

    if form.accepts(request.vars,session):
    for table in db.tables:
    rows=db(db[table].id).select()
    print rows
    open(str(os.sep).join([os.getcwd(), 'applications',
    request.application, 'databases',
    table+'.csv']),'w').write(str(db(db
    [table].id).select()))

    I have code above to create a file..
    How to create the encrypt and decrytp for the file created?thanks

  5. #15
    Join Date
    Dec 2009
    Beans
    Hidden!

    Re: Python function to encrypt and decrypt password

    Quote Originally Posted by NovaAesa View Post
    You could use the bzip2 module. The security wont be very high, but the password can definitely be stored in a non-human readable form.

    PHP Code:
    >>> import bz2
    >>> password = "NoVa52:)"
    >>> 
    encrypted_password bz2.compress(password)
    >>> 
    encrypted_password
    'BZh91AY&SY\xae\x1d\x86!\x00\x00\x02\x1f\x00\x00 \x12\x10\x00\x01\x01\x00 \x00\xa0\x00"\x06\'\xa8C\x02\x12\xe6\xc0\xf1w$S\x85\t\n\xe1\xd8b\x10'
    >>> print bz2.decompress(encrypted_password)
    NoVa52:)
    >>> 
    Thus your password will always be bz2.decompress. so much for encryption. Maybe store an sha-512 sum and do a comparison to validate the data.
    Last edited by d3v1150m471c; November 6th, 2011 at 08:40 AM.

Page 2 of 2 FirstFirst 12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •