From f53001577ee16c9bcc2d6b49932e6719c1fdb99d Mon Sep 17 00:00:00 2001
From: jaideng123 <jaideng123@yahoo.com>
Date: Tue, 26 Aug 2014 13:16:47 -0500
Subject: [PATCH] Increase max length of simple_captcha to 12

---
 config/diaspora.yml.example                              | 2 +-
 config/initializers/setup_simple_captcha.rb              | 9 +++++++--
 .../20140826165533_increase_simple_captcha_limit.rb      | 8 ++++++++
 db/schema.rb                                             | 4 ++--
 4 files changed, 18 insertions(+), 5 deletions(-)
 create mode 100644 db/migrate/20140826165533_increase_simple_captcha_limit.rb

diff --git a/config/diaspora.yml.example b/config/diaspora.yml.example
index e3a8ecc9f5..d9836626ed 100644
--- a/config/diaspora.yml.example
+++ b/config/diaspora.yml.example
@@ -289,7 +289,7 @@ configuration: ## Section
       ## Captcha image size (default='120x20')
       #image_size: '120x20'
 
-      ## Length of captcha text (default=5)
+      ## Length of captcha text (default=5)(max=12)
       #captcha_length: 5
 
       ## Captcha image style (default='simply_green')
diff --git a/config/initializers/setup_simple_captcha.rb b/config/initializers/setup_simple_captcha.rb
index 69ce517c4d..d4b3152346 100644
--- a/config/initializers/setup_simple_captcha.rb
+++ b/config/initializers/setup_simple_captcha.rb
@@ -1,7 +1,12 @@
 SimpleCaptcha.setup do |sc|
   sc.image_size = AppConfig.settings.captcha.image_size
-  sc.length = AppConfig.settings.captcha.captcha_length.to_i
+  value_length = AppConfig.settings.captcha.captcha_length.to_i
+  if value_length <= 12 && value_length > 0 
+    sc.length = value_length
+  else
+    sc.length = 5
+  end
   sc.image_style = AppConfig.settings.captcha.image_style
   sc.distortion = AppConfig.settings.captcha.distortion
   p AppConfig.settings.captcha
-end
\ No newline at end of file
+end
diff --git a/db/migrate/20140826165533_increase_simple_captcha_limit.rb b/db/migrate/20140826165533_increase_simple_captcha_limit.rb
new file mode 100644
index 0000000000..b4d43dd645
--- /dev/null
+++ b/db/migrate/20140826165533_increase_simple_captcha_limit.rb
@@ -0,0 +1,8 @@
+class IncreaseSimpleCaptchaLimit < ActiveRecord::Migration
+  def self.up
+    change_column :simple_captcha_data, :value, :string, :limit => 12
+  end
+  def self.down
+    change_column :simple_captcha_data, :value, :string, :limit => 6
+  end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 007a4077f4..f8f12929b4 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
 #
 # It's strongly recommended that you check this file into your version control system.
 
-ActiveRecord::Schema.define(version: 20140824230505) do
+ActiveRecord::Schema.define(version: 20140826165533) do
 
   create_table "account_deletions", force: true do |t|
     t.string   "diaspora_handle"
@@ -449,7 +449,7 @@ ActiveRecord::Schema.define(version: 20140824230505) do
 
   create_table "simple_captcha_data", force: true do |t|
     t.string   "key",        limit: 40
-    t.string   "value",      limit: 6
+    t.string   "value",      limit: 12
     t.datetime "created_at"
     t.datetime "updated_at"
   end
-- 
GitLab