Autenticación no funciona / Authentication does not work

Notice: This thread is very old.
frankmaniaz
Member | 8
+
0
-
  • Tengo este código, nunca logea aunque tenga las claves correctas
  • I have this code, never login even if the correct key
$values = $form->values;
try {
	        $this->getUser()->login($values->user, $values->pass);
	        $this->redirect('Viz:show');

	    } catch (Nette\Security\AuthenticationException $e) {
	        $this->flashMessage('Error de autentificación', 'danger');
	        $this->redirect('Homepage:');
	    }

Last edited by frankmaniaz (2015-12-25 03:15)

Aurielle
Member | 1281
+
0
-

You have to be more specific about your problem, for example what exceptions are thrown and what's happening. Code snippets (your authenticator) will also help. There's unfortunately nothing that can be seen from the code you posted as there's nothing wrong with it.

frankmaniaz
Member | 8
+
0
-

Estoy usando el authemticador que viene por defecto en sandbox , ningun error solo que no login:

Authemticador'm using the default one in sandbox, no error just not login:

<?php

namespace App\Model;

use Nette;
use Nette\Security\Passwords;


/**
 * Users management.
 */
class UserManager extends Nette\Object implements Nette\Security\IAuthenticator
{
	const
		TABLE_NAME = 'user',
		COLUMN_ID = 'id',
		COLUMN_NAME = 'user',
		COLUMN_PASSWORD_HASH = 'pass',
		COLUMN_ROLE = 'role';


	/** @var Nette\Database\Context */
	private $database;


	public function __construct(Nette\Database\Context $database)
	{
		$this->database = $database;
	}


	/**
	 * Performs an authentication.
	 * @return Nette\Security\Identity
	 * @throws Nette\Security\AuthenticationException
	 */
	public function authenticate(array $credentials)
	{
		list($username, $password) = $credentials;

		$row = $this->database->table(self::TABLE_NAME)->where(self::COLUMN_NAME, $username)->fetch();

		if (!$row) {
			throw new Nette\Security\AuthenticationException('The username is incorrect.', self::IDENTITY_NOT_FOUND);

		} elseif (!Passwords::verify($password, $row[self::COLUMN_PASSWORD_HASH])) {
			throw new Nette\Security\AuthenticationException('The password is incorrect.', self::INVALID_CREDENTIAL);

		} elseif (Passwords::needsRehash($row[self::COLUMN_PASSWORD_HASH])) {
			$row->update(array(
				self::COLUMN_PASSWORD_HASH => Passwords::hash($password),
			));
		}

		$arr = $row->toArray();
		unset($arr[self::COLUMN_PASSWORD_HASH]);
		return new Nette\Security\Identity($row[self::COLUMN_ID], $row[self::COLUMN_ROLE], $arr);
	}


	/**
	 * Adds new user.
	 * @param  string
	 * @param  string
	 * @return void
	 */
	public function add($username, $password)
	{
		try {
			$this->database->table(self::TABLE_NAME)->insert(array(
				self::COLUMN_NAME => $username,
				self::COLUMN_PASSWORD_HASH => Passwords::hash($password),
			));
		} catch (Nette\Database\UniqueConstraintViolationException $e) {
			throw new DuplicateNameException;
		}
	}

}



class DuplicateNameException extends \Exception
{}

Last edited by frankmaniaz (2015-12-26 04:55)

CZechBoY
Member | 3608
+
0
-

This forum is for English speaking people, so please speak only English. Thanks

frankmaniaz
Member | 8
+
0
-

CZechBoY wrote:

This forum is for English speaking people, so please speak only English. Thanks

Authemticador'm using the default one in sandbox, no error just not login:

premek_k
Member | 172
+
+2
-

Check, if you have full length hashed password stored in database table.

frankmaniaz
Member | 8
+
0
-

premek_k wrote:

Check, if you have full length hashed password stored in database table.

thanks premek_k, excellent solution