summaryrefslogtreecommitdiff
path: root/lib/trocla/formats
diff options
context:
space:
mode:
authormh <mh@immerda.ch>2011-07-27 18:43:55 +0200
committermh <mh@immerda.ch>2011-07-27 18:43:55 +0200
commit9146a541ff96b92f4f14c6292307b68dc4673097 (patch)
tree3637ab49056565fad3566d78698634c2a6ab7265 /lib/trocla/formats
initial release of trocla
Diffstat (limited to 'lib/trocla/formats')
-rw-r--r--lib/trocla/formats/md5crypt.rb6
-rw-r--r--lib/trocla/formats/mysql.rb6
-rw-r--r--lib/trocla/formats/pgsql.rb7
-rw-r--r--lib/trocla/formats/plain.rb7
4 files changed, 26 insertions, 0 deletions
diff --git a/lib/trocla/formats/md5crypt.rb b/lib/trocla/formats/md5crypt.rb
new file mode 100644
index 0000000..f52e2a1
--- /dev/null
+++ b/lib/trocla/formats/md5crypt.rb
@@ -0,0 +1,6 @@
+# salted crypt
+class Trocla::Formats::Md5crypt
+ def format(plain_password,options={})
+ plain_password.crypt('$1$' << Trocla::Util.random_str(8) << '$')
+ end
+end \ No newline at end of file
diff --git a/lib/trocla/formats/mysql.rb b/lib/trocla/formats/mysql.rb
new file mode 100644
index 0000000..7fbc3a7
--- /dev/null
+++ b/lib/trocla/formats/mysql.rb
@@ -0,0 +1,6 @@
+class Trocla::Formats::Mysql
+ require 'digest/sha1'
+ def format(plain_password,options={})
+ "*" + Digest::SHA1.hexdigest(Digest::SHA1.digest(plain_password)).upcase
+ end
+end \ No newline at end of file
diff --git a/lib/trocla/formats/pgsql.rb b/lib/trocla/formats/pgsql.rb
new file mode 100644
index 0000000..05c23ce
--- /dev/null
+++ b/lib/trocla/formats/pgsql.rb
@@ -0,0 +1,7 @@
+class Trocla::Formats::Pgsql
+ require 'digest/md5'
+ def format(plain_password,options={})
+ raise "You need pass the username in the options for this format" unless options['username']
+ "md5" + Digest::MD5.hexdigest(plain_password + options['username'])
+ end
+end \ No newline at end of file
diff --git a/lib/trocla/formats/plain.rb b/lib/trocla/formats/plain.rb
new file mode 100644
index 0000000..98797d2
--- /dev/null
+++ b/lib/trocla/formats/plain.rb
@@ -0,0 +1,7 @@
+class Trocla::Formats::Plain
+
+ def format(plain_password,options={})
+ plain_password
+ end
+
+end \ No newline at end of file