Skip to content

Commit

Permalink
Drop dummy "password" type (#896)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored Oct 1, 2021
1 parent 8d8cb49 commit 28238f6
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 59 deletions.
15 changes: 0 additions & 15 deletions bootstrap-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
final class Types
{
public const MONEY = 'money';
public const PASSWORD = 'password';
}

class MoneyType extends DbalTypes\Type
Expand All @@ -28,18 +27,4 @@ public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $pla
}
}

class PasswordType extends DbalTypes\Type
{
public function getName(): string
{
return Types::PASSWORD;
}

public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform): string
{
return DbalTypes\Type::getType(DbalTypes\Types::STRING)->getSQLDeclaration($fieldDeclaration, $platform);
}
}

DbalTypes\Type::addType(Types::MONEY, MoneyType::class);
DbalTypes\Type::addType(Types::PASSWORD, PasswordType::class);
42 changes: 0 additions & 42 deletions docs/fields.rst
Original file line number Diff line number Diff line change
Expand Up @@ -259,45 +259,3 @@ views by default.
.. php:method:: isHidden
Returns true if UI should not render this field in views.


Password (after 1.5.0 release)
==============================

.. php:namespace:: Atk4\Data\Field
.. php:class:: Password
`Field\\Password` is a class that implements proper handling of data passwords.
Without this class your password will be stored **unencrypted**.
Here is how to use it properly::

$user->addField('mypass', [\Atk4\Ui\FormField\Password::class]);

$user->set('mypass', 'secret');
$user->save();

Password is automatically hashed with `password_encrypt` before storing. If you
attempt to load existing record from database and `$user->get('mypass')` you
will always get `NULL`.

There is another way to verify passwords using :php:meth:`Model::compare`::

$user = $user->loadBy('email', $email);
return $user->compare('password', $password);

This should return `true` if your supplied password matches the one that is
stored. Final example::

// class User extends Model

function changePass($old_pass, $new_pass) {

if (!$this->compare('password', $old_pass)) {
throw new Exception('Old password is incorrect');
}

$this->set('password', $new_pass);
$this->save();
}

2 changes: 1 addition & 1 deletion docs/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ a user invokable actions::

$this->addField('name');
$this->addField('email');
$this->addField('password', ['type' => 'password']);
$this->addField('password');

$this->addUserAction('send_new_password');

Expand Down
2 changes: 1 addition & 1 deletion tests-schema/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ protected function init(): void
parent::init();

$this->addField('name');
$this->addField('password', ['type' => 'password']);
$this->addField('password');
$this->addField('is_admin', ['type' => 'boolean']);
$this->addField('notes', ['type' => 'text']);

Expand Down

0 comments on commit 28238f6

Please sign in to comment.