DEV: allow creating users with random passwords via rake

DEV: allow creating users with random passwords via rake

Use: RANDOM_PASSWORD=1 bin/rake admin:create

Handy in conjunction with dev mode /session/username/become.

diff --git a/lib/tasks/admin.rake b/lib/tasks/admin.rake
index d2ff44b..6c8ae0b 100644
--- a/lib/tasks/admin.rake
+++ b/lib/tasks/admin.rake
@@ -56,8 +56,12 @@ task "admin:create" => :environment do
       admin.email = email
       admin.username = UserNameSuggester.suggest(admin.email)
       begin
-        password = ask("Password:  ") { |q| q.echo = false }
-        password_confirmation = ask("Repeat password:  ") { |q| q.echo = false }
+        if ENV["RANDOM_PASSWORD"] == "1"
+          password = password_confirmation = SecureRandom.hex
+        else
+          password = ask("Password:  ") { |q| q.echo = false }
+          password_confirmation = ask("Repeat password:  ") { |q| q.echo = false }
+        end
       end while password != password_confirmation
       admin.password = password
     end

GitHub
sha: abbbcb26

1 Like