Hi all, im a newbie, developing a django online address book application. using mod_python, apache2, postgresql for database.
i have two tables in my database viz login_table and contact_table.. login_table stores username and password.. contact table stores first name, last name, phone number, email id.. i have created a login page that accepts username and password.. i need my application to store the password in encrypted form in the database. how to do password encryption? i have tried some codings ,but that doesnt work out. this is my models.py code. ===models.py==== from django.conf import settings import binascii from os import urandom from base64 import b64encode, b64decode from django.db import models from Crypto.Cipher import ARC4 def get_value(usr_name): def f(self): return login_table.decrypt(getattr(self, 'e_%s'%usr_name)) return f def set_value(usr_name): def f(self, value): setattr(self, 'e_%s'%usr_name, login_table.encrypt(value)) return f class login_table(models.Model): SALT_SIZE = 8 usr_name = models.CharField(max_length=100,unique=True,blank=True) pswd = models.CharField(max_length=50,blank=True) def encrypt(plaintext): salt = urandom(login_table.SALT_SIZE) arc4 = ARC4.new(salt + settings.SECRET_KEY) plaintext = "%3d%s%s" % (len(plaintext),plaintext,urandom(256-len (plaintext))) return "%s$%s" % (b64encode(salt), b64encode(arc4.encrypt (plaintext))) def decrypt(ciphertext): salt, ciphertext = map(b64decode, ciphertext.split('$')) arc4 = ARC4.new(salt + settings.SECRET_KEY) plaintext = arc4.decrypt(ciphertext) return plaintext[3:3+int(plaintext[:3].strip())] def encrypted_property(username): return property(get_value(username), set_value(username)) usr_name = encrypted_property('usr_name') pswd = encrypted_property('pswd') def __unicode__(self): return self.usr_name class contact_table(models.Model): fname = models.CharField(max_length=50,unique=True) lname = models.CharField(max_length=50) ph_num = models.CharField(max_length=50) email = models.EmailField(max_length=75) usr_name = models.ForeignKey(login_table) def __unicode__(self): return '%s%s%s%s' % (self.fname,self.lname,self.ph_num,self.email) How to fix this problem? and is there any pre-defined functions to do password encryption? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---