aboutsummaryrefslogtreecommitdiffstats
path: root/ddns/hash.py
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2014-03-17 04:16:49 +0100
committerMarius Halden <marius.h@lden.org>2014-03-17 04:16:49 +0100
commit7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09 (patch)
tree7bd082fd216e1577440cf1ea599467993c2fef36 /ddns/hash.py
downloadDDNS.py-7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09.tar.gz
DDNS.py-7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09.tar.bz2
DDNS.py-7c575aaa8e98a6aa7eda8d69e2b14d014ee91b09.tar.xz
Initial commit
Diffstat (limited to 'ddns/hash.py')
-rw-r--r--ddns/hash.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/ddns/hash.py b/ddns/hash.py
new file mode 100644
index 0000000..7bb3b3b
--- /dev/null
+++ b/ddns/hash.py
@@ -0,0 +1,23 @@
+import hashlib
+
+algs = [None, 'sha1', 'sha256', 'sha512']
+
+def hash(algo, passwd):
+ if algo == None: # None
+ return passwd
+ if algo == 'sha1': # sha1
+ return sha1(passwd)
+ if algo == 'sha256': # sha256
+ return sha256(passwd)
+ if algo == 'sha512': # sha512
+ return sha512(passwd)
+ return passwd
+
+def sha1(passwd):
+ return hashlib.sha1(passwd).hexdigest()
+
+def sha256(passwd):
+ return hashlib.sha256(passwd).hexdigest()
+
+def sha512(passwd):
+ return hashlib.sha512(passwd).hexdigest()