Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I´m able to specify which password new accounts should have by doing like this, but if I use the output from random_pronouncable_password, it fails. I.e password/username is not recognized.
- # Can you see why?
- account_controller.rb
- def add_user
- @user = User.new(params[:user])
- @user.password_confirmation = @user.password = "secreto" # This works.
- @user.password_confirmation = @user.password = random_pronouncable_password.inspect.to_s # But this does not.
- logger.debug("number is #{@user.number} password: #{@user.password}\n") # I can see the password from random_pronouncable_password.inspect.to_s here.
- if request.post? and @user.save
- flash.now[:notice] = "User #{@user.name} created"
- @user = User.new
- end
- end
- def random_pronouncable_password(size = 3)
- c = %w(b c d f g h j k l m n p qu r s t v w x z ch cr fr nd ng nk nt ph pr rd sh sl sp st th tr)
- v = %w(a e i o u y)
- f, r = true, ''
- (size * 2).times do
- r << (f ? c[rand * c.size] : v[rand * v.size])
- f = !f
- end
- r
- end
Add Comment
Please, Sign In to add comment