diff frontend/mfrontend/utils.py @ 3:79fc37fe85a6

Zabawy z Flaskiem ciąg dalszy, zaczyna to jakoś wyglądać
author michalr
date Tue, 22 Feb 2011 19:25:10 +0000
parents e0061735c327
children 79cf8ca2a0e5
line wrap: on
line diff
--- a/frontend/mfrontend/utils.py	Tue Feb 22 18:37:32 2011 +0000
+++ b/frontend/mfrontend/utils.py	Tue Feb 22 19:25:10 2011 +0000
@@ -1,7 +1,7 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-import random, string
+import random, string, hashlib
 from ConfigParser import SafeConfigParser
 
 def randomString(n):
@@ -16,9 +16,19 @@
     """Funkcja tworząca domyślny plik .ini z ustawieniami aplikacji"""
     config = SafeConfigParser()
     config.add_section('Basic')
-    config.set('Basic', 'Database', '../baza.sqlite')
+    config.set('Basic', 'Database', 'baza.sqlite')
     config.set('Basic', 'Debug', '0')
     config.set('Basic', 'Secret_Key', randomString(10))
+    config.set('Basic', 'HashCrypto', 'sha512')
     with open('config.ini', 'wb') as configfile:
         config.write(configfile)
 
+def hashPassword(password):
+    """Funkcja hashuje hasła."""
+    config = SafeConfigParser()
+    config.read('config.ini')
+    m = hashlib.new(config.get('Basic', 'HashCrypto'))
+    m.update(config.get('Basic', 'Secret_Key'))
+    m.update(password)
+    return m.hexdigest()
+