Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [Cake]Hashowanie haseł
Forum PHP.pl > Forum > PHP > Frameworki
blojayble
Witam. Ostatnio CakePHP mi płata figle, troszkę mnie to irytuje, więc od razu przejdę do rzeczy:
W czym tkwi mój problem? Nie wiadomo jakim cudem cudem w users/login hashują mi się hasła, w niejasny dla mnie sposób.
Sam fakt hashowania w login mnie nie martwi, za to martwi fakt iż jest on tylko w funkcji login, przez co po rejestracji nie mogę się zalogować. Kombinowałem manualnie z hashowaniem, jednak rezultaty nie były zbieżne z tym co wyczyniał login. Próbowałem wyłączyć to hashowanie, jednak starania spełzły na niczym.
Używam cake w wersji 2.1 Stable

Na stronie CakePHP jest napisane:
"In basic authentication, the username and password are transmitted as plain-text to the server."
Więc napisałem sobie w beforeFilter() tak:

  1. $this->Auth->authenticate = array ('Form','Basic');


Więc teoretycznie nie powinno mi automatycznie hashować. Tylko teoretycznie, w praktyce hashuje (tylko hasło i tylko w login)nadal, mimo prób dawania samego Form, tudzież Basic, zmieniania kolejności itp. Próbowałem również metody polegającej na nadpisaniu funkcji hashPasswords w modelu User.


  1. function hashPasswords($data){
  2. debug($data);
  3. return $data; // to raczej nie powinno hashować :)
  4. }

Bezzskutecznie.
W sumie już nie wiem co robić, nie mam dużego doświadczenia w CakePHP, dlatego radzę się was. Żeby rozjaśnić sytuację dodam co ważniejsze pliki:

Funkcja login i beforeFilter z controllera UserController:
  1. function beforeFilter() {
  2.  
  3. //$this->Auth->authenticate = ClassRegistry::init('User');
  4. $this->Auth->authenticate = array ('Form');
  5. $this->Auth->allow('index', 'register', 'login');
  6. $this->Auth->loginRedirect = array( 'controller'=>'users', 'action'=>'index' );
  7. $this->Auth->logoutRedirect = array( 'controller'=>'users', 'action'=>'index' );
  8. $this->Auth->authError = "blond jakis";
  9. $this->Auth->authorize = 'Controller';
  10.  
  11. }
  12.  
  13. function login(){
  14. if ($this->request->is('post')) {
  15. if ($this->Auth->login()) {
  16. return $this->redirect($this->Auth->redirect());
  17. } else {
  18. $this->Session->setFlash(__('Username or password is incorrect'), 'default', array(), 'auth');
  19. }
  20. }
  21. }
  22.  
  23. function logout(){
  24. $this->Session->setFlash("Wylogowalem");
  25. $this->redirect($this->Auth->logout());
  26.  
  27. }
  28.  
  29. function register(){
  30.  
  31.  
  32.  
  33.  
  34. if ($this->request->is('post')) {
  35.  
  36. $this->request->data['User']['password'] = AuthComponent::password($this->request->data['password']);
  37.  
  38. if ($this->User->save($this->request->data)) {
  39. //$this->set('dane', $this->request->data);
  40. return $this->redirect('/users/');
  41. } else {
  42. $this->Session->setFlash(__('blad'), 'default', array(), 'auth');
  43. }
  44. }



Widoczek:
  1. <?php
  2. echo $this->Session->flash('auth');
  3. echo $this->Form->create('User' , array('action'=>'login'));
  4. echo $this->Form->input('username');
  5. echo $this->Form->input('password');
  6. echo $this->Form->end("Zaloguj");
  7.  
  8. ?>



Kod może elegancki nie jest, ale zrobiłem go w celach edukacyjnych,

Z góry dziękuję za pomoc, będę wdzięczny za choćby najmniejsze zainteresowanie sprawą. snitch.gif

Pozdrawiam.
Meritus
Spróbuj manualnie wrzucić datę z requesta do funkcji login, i sam zająć się sprawdzaniem hasła:
  1. $this->User->recursive = -1;
  2. $user = $this->User->find('first', array('conditions' => array('User.email' => $this->request->data['User']['email'])));
  3.  
  4. if ($this->Auth->password($this->request->data['User']['pass']) == $user['User']['pass']) {
  5. $data['id'] = $user['User']['id'];
  6. $data['name'] = $user['User']['name'];
  7. $data['email'] = $user['User']['email'];
  8.  
  9. $this->Auth->login($data);
  10. }



Aha, do mojego kodu niezbędna jest deklaracja:
  1. $this->Auth->fields = array('username' => 'email', 'password' => 'pass');
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.