Permalink
Browse files

cook-194 generate random passwords with OpenSSL::Random

  • Loading branch information...
1 parent ec4fb78 commit 46121e604c4fc9dbffadd62242c4c7312f32486d @jtimberman jtimberman committed Nov 30, 2009
Showing with 10 additions and 6 deletions.
  1. +1 −1 README.rdoc
  2. +8 −4 attributes/redmine.rb
  3. +1 −1 metadata.rb
View
@@ -26,7 +26,7 @@ Opscode cookbooks (http://github.com/opscode/cookbooks/tree/master)
* redmine[:dir] - directory where redmine will be installed.
* redmine[:db][:type] - type of database to use, default is sqlite. mysql or postgresql can be used, but the recipe will need to modified, and the next three attributes adjusted.
* redmine[:db][:user] - database user to connect as, default is redmine.
-* redmine[:db][:password] - password for the user, default is a random string.
+* redmine[:db][:password] - password for the user, default is a random string generated with OpenSSL::Random.random_bytes.
* redmine[:db][:hostname] - hostname of database server, default is localhost.
= USAGE:
View
@@ -15,9 +15,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-db_password = ""
-chars = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
-20.times { |i| db_password << chars[rand(chars.size-1)] }
+require 'openssl'
+
+pw = String.new
+
+while pw.length < 20
+ pw << OpenSSL::Random.random_bytes(1).gsub(/\W/, '')
+end
#database_server = search(:node, "database_master:true").map {|n| n['fqdn']}.first
@@ -28,5 +32,5 @@
set_unless[:redmine][:db][:type] = "sqlite"
set_unless[:redmine][:db][:user] = "redmine"
-set_unless[:redmine][:db][:password] = db_password
+set_unless[:redmine][:db][:password] = pw
set_unless[:redmine][:db][:hostname] = "localhost"
View
@@ -2,7 +2,7 @@
maintainer_email "cookbooks@opscode.com"
license "Apache 2.0"
description "Installs and configures redmine as a Rails app in passenger+apache2"
-version "0.8"
+version "0.9"
%w{ apache2 rails passenger_apache2 mysql sqlite }.each do |cb|
depends cb

0 comments on commit 46121e6

Please sign in to comment.