LdapRecord: [Bug] password not encoded if using custom model
Environment:
- LDAP Server Type: ActiveDirectory
- PHP Version:8.0
Describe the bug:
For some reason $user->unicodepwd is not automatically encoded IF I’m using custom model.
use LdapRecord\Models\Model;
class User extends Model
{
/**
* The object classes of the LDAP model.
*
* @var array
*/
public static $objectClasses = [
'top',
'person',
'organizationalperson',
'user',
];
protected $casts = [
'accountexpires' => 'datetime:windows-int',
];
}
$user = (new User());
$user->unicodepwd = $request->input('password');
dd($user->getModifications());
array:3 [
"attrib" => "unicodepwd"
"modtype" => 1
"values" => array:1 [
0 => "testpassword"
]
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 16 (9 by maintainers)
Hi @vatsake,
I don’t believe you can set a password during creation of an ActiveDirectory account – it must be set after the account exists. Can you confirm if setting the password using your own model actually creates the user with the password you’ve provided?
Also, can you try re-extending the base
Usermodel and attempt setting the password after creation?I.e.
Hi @vatsake,
If you create your own custom
UserActive Directory model, you should either extend the built-inActiveDirectory\Usermodel, or implement the interface and traits that currently exist on that model, namely theHasPasswordtrait:https://github.com/DirectoryTree/LdapRecord/blob/8ad10c26a992b46a265ff84b2d1845003c910a6e/src/Models/ActiveDirectory/User.php#L14-L32
Custom
UserModel:I’d recommend extending the default
Usermodel if you can, as it provides a lot of scaffolding out-of-the-box:Extending Default
UserModel:This will resolve your password encoding issue 👍