summaryrefslogtreecommitdiffstats
path: root/third_party/pyftpdlib/demo/md5_ftpd.py
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/pyftpdlib/demo/md5_ftpd.py')
-rw-r--r--third_party/pyftpdlib/demo/md5_ftpd.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/third_party/pyftpdlib/demo/md5_ftpd.py b/third_party/pyftpdlib/demo/md5_ftpd.py
new file mode 100644
index 0000000..ea51a58a
--- /dev/null
+++ b/third_party/pyftpdlib/demo/md5_ftpd.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python
+# md5_ftpd.py
+
+"""A basic ftpd storing passwords as hash digests (platform independent).
+"""
+
+import md5
+import os
+
+from pyftpdlib import ftpserver
+
+
+class DummyMD5Authorizer(ftpserver.DummyAuthorizer):
+
+ def validate_authentication(self, username, password):
+ hash = md5.new(password).hexdigest()
+ return self.user_table[username]['pwd'] == hash
+
+if __name__ == "__main__":
+ # get a hash digest from a clear-text password
+ hash = md5.new('12345').hexdigest()
+ authorizer = DummyMD5Authorizer()
+ authorizer.add_user('user', hash, os.getcwd(), perm='elradfmw')
+ authorizer.add_anonymous(os.getcwd())
+ ftp_handler = ftpserver.FTPHandler
+ ftp_handler.authorizer = authorizer
+ address = ('', 21)
+ ftpd = ftpserver.FTPServer(address, ftp_handler)
+ ftpd.serve_forever()