Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop dummy "password" type #896

Merged
merged 1 commit into from
Oct 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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