Skip to content

Commit

Permalink
Remove support for WooCommerce OTP
Browse files Browse the repository at this point in the history
  • Loading branch information
pickplugins committed Oct 11, 2023
1 parent 8b90aa6 commit af8cddf
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 55 deletions.
101 changes: 61 additions & 40 deletions includes/functions-mail-otp.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ function user_verification_login_form_otp()
*/


add_action('woocommerce_login_form', 'user_verification_woocommerce_login_form_otp_scripts', 99);
//add_action('woocommerce_login_form', 'user_verification_woocommerce_login_form_otp_scripts', 99);
function user_verification_woocommerce_login_form_otp_scripts()
{

Expand Down Expand Up @@ -374,26 +374,6 @@ function user_verification_check_password_otp_default_login($check, $password, $
}


//add_filter('check_password', 'user_verification_check_password_otp_wc_login', 99, 4);
function user_verification_check_password_otp_wc_login($check, $password, $hash, $user_id)
{

$user_verification_settings = get_option('user_verification_settings');
$enable_wc_login = isset($user_verification_settings['email_otp']['enable_wc_login']) ? $user_verification_settings['email_otp']['enable_wc_login'] : 'no';

if ($enable_wc_login != 'yes') return $check;

// error_log('user_verification_check_password_otp_wc_login');

// error_log($check);
// error_log($password);
// error_log($hash);
// error_log($user_id);

//$errors = [];

return true;
}



Expand All @@ -408,43 +388,84 @@ function user_verification_check_password_otp_wc_login($check, $password, $hash,
add_filter('wp_authenticate_user', 'user_verification_auth_otp_default_login', 10, 2);
function user_verification_auth_otp_default_login($user, $password)
{
require_once(ABSPATH . 'wp-includes/class-phpass.php');
$user_id = isset($user->ID) ? $user->ID : '';
$saved_otp = get_user_meta($user_id, 'uv_otp', true);
$error = new WP_Error();

$wp_hasher = new PasswordHash(8, TRUE);

$isvalidPass = false;
if ($wp_hasher->CheckPassword($password, $user->user_pass)) {
error_log("YES, Matched");
$isvalidPass = true;
} else {
error_log("No, Wrong Password");
$isvalidPass = false;
}
error_log($isvalidPass);
// error_log('$user->user_pass: ' . $user->user_pass);


// error_log('wp_hash_password: ' . wp_hash_password($password));
// error_log('$password: ' . $password);
// error_log('$user_id: ' . $user_id);
// error_log('user_verification_auth_otp_default_login');

$user_verification_settings = get_option('user_verification_settings');
$enable_default_login = isset($user_verification_settings['email_otp']['enable_default_login']) ? $user_verification_settings['email_otp']['enable_default_login'] : 'no';
$enable_wc_login = isset($user_verification_settings['email_otp']['enable_wc_login']) ? $user_verification_settings['email_otp']['enable_wc_login'] : 'no';
$allow_password = isset($user_verification_settings['email_otp']['allow_password']) ? $user_verification_settings['email_otp']['allow_password'] : 'yes';

if ($enable_default_login != 'yes') return $user;
if ($enable_wc_login != 'yes') return $user;
error_log('error - 1 ');

if ($allow_password == 'yes') {

$error = new WP_Error();
if ($isvalidPass) {
return $user;
} else {

if ($enable_default_login != 'yes') return $user;

$user_id = isset($user->ID) ? $user->ID : '';
//$uv_otp = isset($_POST['pwd']) ? sanitize_text_field($_POST['pwd']) : '';
if (empty($password)) {
$error->add('otp_empty', __('OTP should not empty. 1', 'user-verification'));
}

if (empty($saved_otp)) {
$error->add('otp_not_found', __('OTP not found.', 'user-verification'));
}

if (empty($password)) {
$error->add('otp_empty', __('OTP should not empty. 1', 'user-verification'));
}
if ($saved_otp != $password) {
$error->add('otp_not_match', __('OTP is not correct.', 'user-verification'));
}

$saved_otp = get_user_meta($user_id, 'uv_otp', true);
if (!$error->has_errors()) {
return $user;
} else {
return $error;
}
}
} else {

if (empty($saved_otp)) {
$error->add('otp_not_found', __('OTP not found.', 'user-verification'));
}
if ($enable_default_login != 'yes') return $user;

if (empty($password)) {
$error->add('otp_empty', __('OTP should not empty. 1', 'user-verification'));
}

if ($saved_otp != $password) {
$error->add('otp_not_match', __('OTP is not correct.', 'user-verification'));
}
if (empty($saved_otp)) {
$error->add('otp_not_found', __('OTP not found.', 'user-verification'));
}

if ($saved_otp != $password) {
$error->add('otp_not_match', __('OTP is not correct.', 'user-verification'));
}

if (!$error->has_errors()) {
return $user;
} else {
return $error;
if (!$error->has_errors()) {
return $user;
} else {
return $error;
}
}
}

Expand Down
39 changes: 26 additions & 13 deletions includes/settings-hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,7 @@ function user_verification_settings_content_email_otp()
$enable_default_register = isset($user_verification_settings['email_otp']['enable_default_register']) ? $user_verification_settings['email_otp']['enable_default_register'] : 'no';
$length = isset($user_verification_settings['email_otp']['length']) ? $user_verification_settings['email_otp']['length'] : 6;
$character_source = isset($user_verification_settings['email_otp']['character_source']) ? $user_verification_settings['email_otp']['character_source'] : ['uppercase', 'lowercase'];
$allow_password = isset($user_verification_settings['email_otp']['allow_password']) ? $user_verification_settings['email_otp']['allow_password'] : 'yes';

//$password = user_verification_random_password($length, $character_source)

Expand All @@ -743,29 +744,41 @@ function user_verification_settings_content_email_otp()
);

$settings_tabs_field->generate_field($args);


$args = array(
'id' => 'enable_wc_login',
'id' => 'allow_password',
'parent' => 'user_verification_settings[email_otp]',
'title' => __('Enable on WooCommerce login', 'user-verification'),
'details' => __('Enable OTP on WooCommerce login page. every time a user try to login via WooCommerce login form will require a OTP send via mail.', 'user-verification'),
'disabled' => ($enable_default_login != 'yes') ? true : false,
'disabledMessage' => 'Please enable OTP on default login first',
'conditions' => array(
'field' => 'user_verification_settings[email_otp][enable_default_login]',
'value' => 'yes',
'type' => '='
),
'title' => __('Allow Passowrd', 'user-verification'),
'details' => __('Allow password in OTP field', 'user-verification'),
'type' => 'select',
'value' => $enable_wc_login,
'value' => $allow_password,
'default' => '',
'args' => array('yes' => __('Yes', 'user-verification'), 'no' => __('No', 'user-verification')),
);

$settings_tabs_field->generate_field($args);


// $args = array(
// 'id' => 'enable_wc_login',
// 'parent' => 'user_verification_settings[email_otp]',
// 'title' => __('Enable on WooCommerce login', 'user-verification'),
// 'details' => __('Enable OTP on WooCommerce login page. every time a user try to login via WooCommerce login form will require a OTP send via mail.', 'user-verification'),
// 'disabled' => ($enable_default_login != 'yes') ? true : false,
// 'disabledMessage' => 'Please enable OTP on default login first',
// 'conditions' => array(
// 'field' => 'user_verification_settings[email_otp][enable_default_login]',
// 'value' => 'yes',
// 'type' => '='
// ),
// 'type' => 'select',
// 'value' => $enable_wc_login,
// 'default' => '',
// 'args' => array('yes' => __('Yes', 'user-verification'), 'no' => __('No', 'user-verification')),
// );

// $settings_tabs_field->generate_field($args);


$args = array(
'id' => 'enable_default_register',
'parent' => 'user_verification_settings[email_otp]',
Expand Down
5 changes: 4 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Tags: User Verification
Requires at least: 4.1
Tested up to: 6.3
Stable tag: 2.0.19
Stable tag: 2.0.20
License: GPLv2 or later
License URI: http://www.gnu.org/licenses/gpl-2.0.html

Expand Down Expand Up @@ -138,6 +138,9 @@ Plugin is translation ready , please find the 'en.po' for default translation fi



= 2.0.20 =
* 2023-10-11 fix - Remove support for WooCommerce OTP

= 2.0.19 =
* 2023-10-08 fix - Double verification mail for WP User Manager plugin issue fixed.

Expand Down
2 changes: 1 addition & 1 deletion user-verification.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: User Verification
Plugin URI: http://pickplugins.com
Description: Verify user before access on your website.
Version: 2.0.19
Version: 2.0.20
Text Domain: user-verification
Domain Path: /languages
Author: PickPlugins
Expand Down

0 comments on commit af8cddf

Please sign in to comment.