string - changing data in a struct in python -


i pretty new in python, , have problem don't know how solve.

for example, have struct members such administrator, berit, etc:

default_data = { 'administrator': {     'name': 'admin',     'pw': 'secret',     'is_author': false,     'is_admin': true } 'berit': {      'name': 'berit',     'pw': 'apa',     'is_author': false,     'is_admin': false  } 

this data accessible via method method:

def defaultdata(): """provides default data gruyere."""  return copy.deepcopy(default_data) 

i want md5 hash on passwords not in plaintext, have no idea how access fields such 'pw' , reassign new value in python.

here's guess might be:

stored_data = data.defaultdata() member in stored_data:    field in member:        if field=='pw':            'pw' = md5.new(salt+pw).hexdigest()    // how access value? 

the values in stored_data dictionaries. iterate on values , apply algorithm:

stored_data = data.defaultdata() data in stored_data.values():     data['pw'] = md5(salt + data['pw']).hexdigest()  pprint import pprint pprint(stored_data) 

output

{'administrator': {'is_admin': true,                    'is_author': false,                    'name': 'admin',                    'pw': '33e7cb694fb6fb2f848af6774d9ff138'},  'berit': {'is_admin': false,            'is_author': false,            'name': 'berit',            'pw': '00c10978330d65eb0cb739a629b6ed15'}} 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -