for passwords I usually use a descriptor:

def _set_password(self, pw):
     self._password = sha1(pw)

def _get_password(self):
    return self._password

password = property(_get_password, _set_password)

the mapper would map '_password' to customer_table.c.password.   Above  
is assuming one-way encryption for the password which is typical.

the other way to do it would be to use a TypeDecorator.

On Feb 15, 2009, at 5:57 AM, Jessica Meyer wrote:

>
> Hi there
>
> I just completed the Object Relational Tutorial [1] and want to use
> that knowledge to start a little project of mine.
>
> So I have a customer table in my database, and I want a "helper
> function" that converts the password to a SHA1 hash and performs other
> things. This is just a simple example and I wanted to ask you guys how
> I should do this.
>
> So my table just looks like this:
>
> customer_table = Table(
>    'customer', metadata,
>    Column('id', Integer, primary_key=True),
>    Column('login', Unicode(25), nullable=False),
>    Column('password', Unicode(40), nullable=False),
>    Column('firstname', Unicode(40), nullable=False),
>    Column('lastname', Unicode(40), nullable=False),
>    Column('street', Unicode(40)),
>    Column('zip', Unicode(10)),
>    Column('city', Unicode(40)),
>    Column('country_id', Integer, ForeignKey('country.id')),
>    Column('phonebusiness', Unicode(20)),
>    Column('phoneprivate', Unicode(20)),
>    Column('phonemobile', Unicode(20)),
>    )
>
> Then follows a class definition "Customer", from what I've learnt in
> the tutorial:
>
> class Customer(object):
>    def __init__(self, login, password, firstname, lastname, street,
> plz, city):
>        self.login = login
>        self.password = password
>        self.firstname = firstname
>        self.lastname = lastname
>        self.street = street
>        self.zip = zip
>        self.city = city
>        self.phonebusiness = phonebusiness
>        self.phoneprivate = phoneprivate
>        self.phonemobile = phonemobile
>
>    def __repr__(self):
>        return "<Customer('%s', '%s')>" % (self.login, self.password)
>
> I know how to query the database, and to add a new database entry. But
> I really wanna know where my helper code goes. My idea is that there
> is a function addCustomer() in the Customer class, but I tried this
> out and it didnt work. Any suggestions or examples how to proceed?
>
> Thanks!
>
> [1] http://www.sqlalchemy.org/docs/05/ormtutorial.html
>
> >


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to