# How to generate password automatically using authlogic

**URL:** <https://www.ruby-forum.com/t/how-to-generate-password-automatically-using-authlogic/197099>\
**Category:** Rails\
**Created:** [September 24, 2009, 4:33am UTC](https://www.ruby-forum.com/t/how-to-generate-password-automatically-using-authlogic/197099 "2009-09-24T04:33:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [September 24, 2009, 4:33am UTC](https://www.ruby-forum.com/t/how-to-generate-password-automatically-using-authlogic/197099/1 "2009-09-24T04:33:20Z")

</div>

I have problem , i want to generate password automatically  
where can i manipulate :password and :confirm\_password in action create

def create  
@user = User.new(params[:user])  
if @user.save  
flash[:notice] = “Registration successful.”  
redirect\_to root\_url  
else  
render :action =\> ‘new’  
end  
end

---

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [September 24, 2009, 11:47pm UTC](https://www.ruby-forum.com/t/how-to-generate-password-automatically-using-authlogic/197099/2 "2009-09-24T23:47:48Z")

</div>

Have you tried just setting @user.password and  
@user.password\_confirmation (or equivalent) before the @user.save  
part?

–Matt J.

On Sep 23, 10:33 pm, “Thriving K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![thriving](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ecae2f/32.png) [@thriving](https://www.ruby-forum.com/u/thriving)\
**Post date:** [September 25, 2009, 4:57am UTC](https://www.ruby-forum.com/t/how-to-generate-password-automatically-using-authlogic/197099/3 "2009-09-25T04:57:16Z")

</div>

Matt J. wrote:

> Have you tried just setting @user.password and  
> @user.password\_confirmation (or equivalent) before the @user.save  
> part?
> 
> –Matt J.
> 
> On Sep 23, 10:33ï¿½pm, “Thriving K.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

Thank you, i can fix it now.  
i have to put

= f.hidden\_field :password,:value=\>“”  
= f.hidden\_field :password\_confirmation,:value=\>“”

in form first and then i can type

@user.password=@user.password\_confirmation=random\_password in controller  
before save
