質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

Q&A

解決済

1回答

2438閲覧

cakePHPの2.5でパスワードが暗号化されない

gomengo

総合スコア51

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

CakePHP

CakePHPは、PHPで書かれたWebアプリケーション開発用のフレームワークです。 Ruby on Railsの考え方を多く取り入れており、Railsの高速性とPHPの機動性を兼ね備えています。 MVCやORMなどを「規約優先の考え方」で利用するため、コードを書く手間を省くことができます。 外部のライブラリに依存しないので、単体での利用が可能です。

1グッド

0クリップ

投稿2016/01/06 13:17

cakePHPのバージョン2.5を使ってAuthコンポーネントで認証をつけようとしています。

さくらインターネットを利用しているのですが、
usersテーブルのパスワードが暗号化されません。

考えられる理由としてどのような原因が考えられるのでしょうか?

usersコントローラーのソースは下記です。
初期データのusersのデータを登録しているので、
http://aaa.jp/users/add を利用し、情報を登録しようとしています。
申し訳ございませんが、よろしくお願い致します。

php

1<?php 2App::uses('AppController', 'Controller'); 3/** 4 * Users Controller 5 * 6 * @property User $User 7 * @property PaginatorComponent $Paginator 8 */ 9class UsersController extends AppController { 10 11 12 public $helpers = array('Html', 'Form'); 13/** 14 * Components 15 * 16 * @var array 17 */ 18 public $components = array( 19 'Paginator', 20 // 以下、Authコンポーネント設定 21 'Auth' => array( 22 // ログインページのパス 23 'loginAction' => array('controller' => 'users', 'action' => 'login'), 24 25 // ログイン後のページを指定 26 'loginRedirect' => array('controller' => 'accounts', 'action' => 'index'), 27 28 // ログアウト後の移動先 29 'logoutRedirect' => array('controller' => 'users', 'action' => 'login'), 30 31 // 未ログイン時のメッセージ 32 'authError' => 'あなたのお名前とパスワードを入力して下さい。', 33 ) 34 ); 35 36 public function beforeFilter(){ 37 //親クラスのbeforeFilterの読み込み 38// parent::beforeFilter(); 39 //認証不要のページの指定 40// $this->Auth->allow('login','add'); 41 $this->Auth->allow('login','logout','add'); 42 } 43 44 public function login() 45 { 46 // titleタグ 47 $this->set('title_for_layout', 'ログイン'); 48 49 if ($this->request->is('post')){ 50 if ( $this->Auth->login() ) { 51 $this->redirect($this->Auth->redirect('/accounts/index')); 52 } else { 53 $this->Session->setFlash(__('ユーザ名、メールアドレス、パスワードが不正です。')); 54 } 55 } 56 } 57 58 public function logout(){ 59 $this->Auth->logout(); 60 $this->Session->destroy(); //セッションを完全削除 61 $this->Session->setFlash(__('ログアウトしました')); 62 $this->redirect(array('action' => 'login')); 63 } 64 65/** 66 * index method 67 * 68 * @return void 69 */ 70 public function index() { 71 $this->User->recursive = 0; 72 $this->set('users', $this->Paginator->paginate()); 73 } 74 75/** 76 * view method 77 * 78 * @throws NotFoundException 79 * @param string $id 80 * @return void 81 */ 82 public function view($id = null) { 83 if (!$this->User->exists($id)) { 84 throw new NotFoundException(__('Invalid user')); 85 } 86 $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); 87 $this->set('user', $this->User->find('first', $options)); 88 } 89 90/** 91 * add method 92 * 93 * @return void 94 */ 95 public function add() { 96 if ($this->request->is('post')) { 97 $this->User->create(); 98 if ($this->User->save($this->request->data)) { 99 $this->Session->setFlash(__('The user has been saved.')); 100 return $this->redirect(array('action' => 'index')); 101 } else { 102 $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 103 } 104 } 105 106 } 107 108/** 109 * edit method 110 * 111 * @throws NotFoundException 112 * @param string $id 113 * @return void 114 */ 115 public function edit($id = null) { 116 if (!$this->User->exists($id)) { 117 throw new NotFoundException(__('Invalid user')); 118 } 119 if ($this->request->is(array('post', 'put'))) { 120 if ($this->User->save($this->request->data)) { 121 $this->Session->setFlash(__('The user has been saved.')); 122 return $this->redirect(array('action' => 'index')); 123 } else { 124 $this->Session->setFlash(__('The user could not be saved. Please, try again.')); 125 } 126 } else { 127 $options = array('conditions' => array('User.' . $this->User->primaryKey => $id)); 128 $this->request->data = $this->User->find('first', $options); 129 } 130 131 } 132 133/** 134 * delete method 135 * 136 * @throws NotFoundException 137 * @param string $id 138 * @return void 139 */ 140 public function delete($id = null) { 141 $this->User->id = $id; 142 if (!$this->User->exists()) { 143 throw new NotFoundException(__('Invalid user')); 144 } 145 $this->request->allowMethod('post', 'delete'); 146 if ($this->User->delete()) { 147 $this->Session->setFlash(__('The user has been deleted.')); 148 } else { 149 $this->Session->setFlash(__('The user could not be deleted. Please, try again.')); 150 } 151 return $this->redirect(array('action' => 'index')); 152 } 153} 154
mhashi👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

自己解決

Userモデルを下記のようにしたらうまくいきました。

php

1<?php 2App::uses('AppModel', 'Model'); 3/** 4 * User Model 5 * 6 */ 7class User extends AppModel { 8 9/** 10 * Display field 11 * 12 * @var string 13 */ 14 public $displayField = 'id'; 15 16 public function beforeSave($options = array()) { 17 if (isset($this->data[$this->alias]['password'])) { 18 $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']); 19 } 20 return true; 21} 22 23}

投稿2016/01/06 13:34

gomengo

総合スコア51

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問