2011-06-19 12 views
2

以下のコードを使用してユーザパスワードを更新する場合、このPostgreSQL機能crypt('<password>', gen_salt('bf'))を使用する方法はありますか? update_all方法 -データベース機能を呼び出してユーザの詳細を更新する

def update 
    @player = Player.find(params[:id]) 

    respond_to do |format| 
    if @player.update_attributes(params[:player]) 
     flash[:notice] = 'Player was successfully updated.' 
     format.html { redirect_to(@player) } 
     format.xml { head :ok } 
    else 
     format.html { render :action => "edit" } 
     format.xml { render :xml => @player.errors, :status => :unprocessable_entity } 
    end 
    end 
end 
+3

は、なぜあなたは、データストアへのオフアプリケーション関連の懸念をプッシュします:

ですから、このような何かを行うことができますPostgresの暗号方式を持つプレイヤーのパスワードを更新するには?コールごとにパフォーマンスが向上したとしても、規模を拡大しようとすると、データベースは通常ボトルネックになります。 – coreyward

+1

@coreyward:本当ですが、質問はまだ興味深いです。 :-) –

答えて

1

はアップデートで、純粋なSQLを使用するために、少なくとも1つの方法があります。

Player.update_all "password = crypt('<password>', gen_salt('bf'))", "id = #{params[:id]}" 
関連する問題