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

Update password.php #2229

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
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
41 changes: 30 additions & 11 deletions classes/fields/password.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,19 @@ public function options () {
'default' => 255,
'type' => 'number',
'help' => __( 'Set to -1 for no limit', 'pods' )
)/*,
),
self::$type . '_hash' => array(
'label' => __( 'Hash', 'pods' ),
'default' => 1,
'type' => 'boolean',
'help' => __( 'Securely hash passwords when storing them', 'pods' )
),
self::$type . '_salt' => array(
'label' => __( 'Salt', 'pods' ),
'default' => "",
'type' => 'string',
'help' => __( 'Used for salting the hashes of secure fields', 'pods' )
)/*,
self::$type . '_size' => array(
'label' => __( 'Field Size', 'pods' ),
'default' => 'medium',
Expand All @@ -85,14 +97,19 @@ public function options () {
* @since 2.0
*/
public function schema ( $options = null ) {
$length = (int) pods_var( self::$type . '_max_length', $options, 255 );
if( pods_var( self::$type . '_hash', $options ) ) {
return 'VARCHAR(32)';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line should be $length = 32;

}
else {
$length = (int) pods_var( self::$type . '_max_length', $options, 255 );

$schema = 'VARCHAR(' . $length . ')';
$schema = 'VARCHAR(' . $length . ')';

if ( 255 < $length || $length < 1 )
$schema = 'LONGTEXT';
if ( 255 < $length || $length < 1 )
$schema = 'LONGTEXT';

return $schema;
return $schema;
}
}

/**
Expand Down Expand Up @@ -174,12 +191,14 @@ public function validate ( $value, $name = null, $options = null, $fields = null
* @since 2.0
*/
public function pre_save ( $value, $id = null, $name = null, $options = null, $fields = null, $pod = null, $params = null ) {
$length = (int) pods_var( self::$type . '_max_length', $options, 255 );
$length = (int) pods_var( self::$type . '_max_length', $options, 255 );

if ( 0 < $length && $length < pods_mb_strlen( $value ) ) {
$value = pods_mb_substr( $value, 0, $length );
}
if ( 0 < $length && $length < pods_mb_strlen( $value ) )
$value = pods_mb_substr( $value, 0, $length );

return $value;
if ( pods_var( self::$type . '_hash', $options ) )
return hash_pbkdf2('sha1', $value, pods_var( self::$type . '_salt', $options ), 1, 32);
else
return $value;
}
}