Guest User

Untitled

a guest
Mar 10th, 2018
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. # 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.
  2. # Can you see why?
  3.  
  4.  
  5. account_controller.rb
  6. def add_user
  7. @user = User.new(params[:user])
  8. @user.password_confirmation = @user.password = "secreto" # This works.
  9. @user.password_confirmation = @user.password = random_pronouncable_password.inspect.to_s # But this does not.
  10. logger.debug("number is #{@user.number} password: #{@user.password}\n") # I can see the password from random_pronouncable_password.inspect.to_s here.
  11. if request.post? and @user.save
  12. flash.now[:notice] = "User #{@user.name} created"
  13. @user = User.new
  14. end
  15. end
  16.  
  17. def random_pronouncable_password(size = 3)
  18. 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)
  19. v = %w(a e i o u y)
  20. f, r = true, ''
  21. (size * 2).times do
  22. r << (f ? c[rand * c.size] : v[rand * v.size])
  23. f = !f
  24. end
  25. r
  26. end
Add Comment
Please, Sign In to add comment