Checking if password field has a value set


#1

Hi There,

I am using the Password Field provided atk4\login. Works very well except one thing: I try to determine if a password was set at all (Database entry != null).

But I can not access the password value from my model at all.
The model:

   ...
   function init() {
		parent::init();

		$this->addFields([
			['name', 		'type'=>'string', 	'system' => true],
			['firstname', 	'type'=>'string', 	'caption' => 'Vorname'],
			['lastname', 	'type'=>'string', 	'caption' => 'Nachname'],
			['username', 	'type'=>'string', 	'caption' => 'Benutzername'],
		]);

		$p = new \atk4\login\Field\Password();
		$this->addField('password', [$p, 'caption' => 'Passwort', 'system' => true]);
   ...

Accessing the field like this always returns null:

$model->get('password');

Directly accessing the field also does not help:

$p = $eoo_user->getElement('password');
	var_dump($p);

//Output:
object(atk4\login\Field\Password)#168 (8) {
  ["short_name"]=>
  string(8) "password"
  ["value"]=>
  NULL
  ["type"]=>
  string(8) "password"
  ["system"]=>
  bool(true)
  ["never_persist"]=>
  bool(false)
  ["never_save"]=>
  bool(false)
  ["read_only"]=>
  bool(false)
  ["ui"]=>
  array(0) {
  }
}

Value here also is NULL, though in the database its properly stored.

Best regards
Philipp


#2

Password tries to protect it’s value, so you can’t read it directly. You can verify it though. Perhaps we can make isset($model[‘password_field’]) work or have password return some non-null value.

This should probably be reported as a ticket into atk4/login. You can also extend Password field and add method for accessing it’s protected properly.

(shouldn’t this be declared as “protected” ?)