Quantcast
Channel: Recent Discussions — DataTables forums
Viewing all articles
Browse latest Browse all 81728

Empty Password Field, disable writing to database

$
0
0

I have a password field that when a new user is created I want to write the password to the database. That works fine and encrypts the password using the following.

$out=Editor::inst( $db, 'users' )
    ->field(
        Field::inst( 'password' )
            ->get( false ) // never read from the db
                ->setFormatter ( function ( $val, $data ) {
                    return crypt( $val, '$somerandomsalthere$' );
                }),
...

However if you edit an existing users information and do not specify a password a null is encrypted and the user's password is changed. I don't want to encrypt a blank/null password only a change such as a password reset.

I have been trying to figure this out and only have gotten this far unsuccessfully...

$out=Editor::inst( $db, 'users' )
    ->field(
        Field::inst( 'password' )
            ->get( false ) // never read from the db
                ->validator( function ( $editor, $action, $data, $val ) {
                    if ( $action === Editor::ACTION_CREATE ) {
                        ->setFormatter ( function ( $val, $data ) {
                            return crypt( $val, '$somerandomsalthere$' );
                        })
                    } else if ( $action === Editor::ACTION_EDIT ) {
                        Field( 'users' ).set(false);
                        return;
                    }
                } ),
...

It doesn't like the ->setFormatter. Evidently it doesn't belong there. How else can I accomplish this?


Viewing all articles
Browse latest Browse all 81728

Trending Articles