Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
13871 Widoki

I would like record a field (wich is a password) encrypted in my database. I have to encrypt it directly inside my module not in my PostgreSQL database. I did the following :

import md5
import os
from openerp.osv import osv, fields


###### Encrypton of passwords ######

CRYPT64 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'

def make_salt():
    sbytes = os.urandom(8)
    return ''.join([CRYPT64[ord(b) & 0x3f] for b in sbytes])

def md5crypt(password, salt, magic='$1$'):
    if salt is None:
        salt = make_salt()

    m = md5.new()
    m.update(password + magic + salt)

    mixin = md5.new(password + salt + password).digest()
    for i in range(0, len(password)):
        m.update(mixin[i % 16])

    # Then something really weird...
    # Also really broken, as far as I can tell.  -m
    i = len(password)
    while i:
        if i & 1:
            m.update('\x00')
        else:
            m.update(password[0])
        i >>= 1

    final = m.digest()
    return final

md5crypt(pass_pid)

###### Creation of password table ######
class password(osv.osv):

    _inherit = 'res.partner'

    _columns = {
        'passwords': fields.one2many('password.table','name_pid','user_pid')

   }
password()

class password_table(osv.osv):
    _name="password.table"

    _columns = {
            'name_pid':fields.many2one('res.partner', 'name', required=True),
            'user_pid':fields.char("UserName", size=128, required=True),
            'host_pid':fields.char("IP/HostName", size=128, required=True),
            'pass_pid':fields.function(md5crypt, type="text", string="password", size=128, required=True),
            'com_pid':fields.text("Comment")
        }
password_table()

The error is about my parameters but I don't know at all how to modify that!

Awatar
Odrzuć

can you please post the error you are getting? That would help give you a better answer.

Autor

I'm getting this error: "File "/home/integration/oe7_1/addons/password_module/password.py", line 59, in <module> md5crypt(pass_pid) NameError: name 'pass_pid' is not defined"

Najlepsza odpowiedź

This is a python programming question, not an openerp issue/ error/ question. I will try to point you in the right direction, but you are going to have to get someone that knows how to program python to do this programming for you, this forum is for openERP questions.

First you should move the encryption function into class password_table(osv.osv):

Second, you want to use this function to encode and store the password, so you have to create a function that will encode when saving the field and another for viewing it.

read how to use functions here: https://doc.openerp.com/6.0/developer/2_5_Objects_Fields_Methods/field_type/#functional-fields

'pass_pid':fields.function( _view_function, fnct_inv=_store_function, type="text", string="password", size=128, required=True),

Third you cannot just cut and paste code from other sources, you have to massage it into openERP so you will have to rewrite the function accordingly. Your functions will have to start something like this:

def _store_function(self, cr, uid, id, name, value, args=None, context=None):

If you need help beyond this you should contact an openERP partner to write the module for you. Custom coding is a service they are happy to provide.

Awatar
Odrzuć
Autor

Thanks a million Patently, I will see what can I do with that!

Powiązane posty Odpowiedzi Widoki Czynność
0
mar 15
5113
2
lut 24
1631
1
mar 20
3628
3
maj 25
1623
1
kwi 25
1228