Nasouh Posted February 5, 2020 Share Posted February 5, 2020 Hi guys, Am wondering if it's possible to login with Phone Number instead of Email? If not Is there any Module for this feature ? Thanks for help 0 Quote Link to comment Share on other sites More sharing options...
zomex Posted February 6, 2020 Share Posted February 6, 2020 Hello, There are a lot of modules available to verify each login with a phone number but I can't find any that replace the email with phone number for the login. I believe it would be possible to do with a custom module but it's not a feature that is available by default. 0 Quote Link to comment Share on other sites More sharing options...
Nasouh Posted February 6, 2020 Author Share Posted February 6, 2020 Thanks for reply @zomex , yes i found the same thing, thanks for help. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted August 22, 2020 Share Posted August 22, 2020 Yes there is module to login using Username 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 22, 2020 Share Posted August 22, 2020 You can use this hook: <?php // THIS IS BAD PRACTICE - MULTIPLE USERS CAN HAVE THE SAME PHONE NUMBER // THIS IS BAD PRACTICE - MULTIPLE USERS CAN HAVE THE SAME PHONE NUMBER // THIS IS BAD PRACTICE - MULTIPLE USERS CAN HAVE THE SAME PHONE NUMBER // THIS IS BAD PRACTICE - MULTIPLE USERS CAN HAVE THE SAME PHONE NUMBER // THIS IS BAD PRACTICE - MULTIPLE USERS CAN HAVE THE SAME PHONE NUMBER // THIS IS BAD PRACTICE - MULTIPLE USERS CAN HAVE THE SAME PHONE NUMBER use WHMCS\Database\Capsule; add_hook('ClientLoginShare', 1, function ($vars) { // Define username and password. Username is whatever the user enters in the 'email address' field. $username = $vars['username']; $password = $vars['password']; // Let's see if the user is logging in using an email address. If not, let's see if we can find the user's phone number in the database and allow them to login this way. if (!filter_var($username, FILTER_VALIDATE_EMAIL)) { $users = Capsule::table('tblclients') ->select('email') ->where('phonenumber', $username) ->get(); // If there's multiple users with the same phone number, allow _none_ of them to login by using their phone numbers. // They will only be able to login using email address in that case if (sizeof($users) > 1) { return false; } // Set the user's email address foreach($users as $user){ $email = $user->email; } // Documentation: https://developers.whmcs.com/api-reference/validatelogin/ $command = 'ValidateLogin'; $postData = array( 'email' => $email, 'password2' => $password, ); // Check if login is valid - if it is, log them in using email address $isValid = localAPI($command, $postData); if($isValid['result'] == "true") { return array( 'email' => $email, ); } } }); add_hook('ClientAreaFooterOutput', 1, function($vars) { // Change login input field to allow any text $changeLoginInput = '<script>$( document ).ready(function() { $("#inputEmail").prop({type:"text"}); });</script>'; return $changeLoginInput; }); Although it's very bad practice. Multiple users can have the same phone number. I've implemented a piece of code that will force users to login with email address if the same phone number exists for multiple accounts - but use it at your own risk. I haven't tested the script 100% - please make sure you test it before you use it. 1 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted August 23, 2020 Share Posted August 23, 2020 Yes, Multiple users can have the same phone number. But if they can login using only phone no. or only a Username - example for all accounts. Username - exampleadmin Phone - 999990000 A single user may have four companies and he / she has to remember all four usernames / email id's . If such users can login using only one mobile number and a single password then it would always be helpful in my opinion. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 23, 2020 Share Posted August 23, 2020 (edited) There's no way you can do that. No way whatsoever. Each user is its own user. You can't log in to multiple accounts at once. I might be misunderstanding you. How would you think it should work? Edit: With WHMCS v8., you'll be able to access multiple accounts from one user. What you're suggesting doesn't work, though. Edited August 23, 2020 by DennisHermannsen 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted August 23, 2020 Share Posted August 23, 2020 Okay it it would support one login multiple accounts then it's fine. However I think that what I am thinking should work out with a hook... 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted August 23, 2020 Share Posted August 23, 2020 No, it won't. There's no way to display information for multiple accounts at once with a single user in WHMCS. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 2, 2020 Share Posted September 2, 2020 Hi @DennisHermannsen, can we add the mobile number for clients as showed below example ? 9980989800-1 9980989800-2 Thanks 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 2, 2020 Share Posted September 2, 2020 Sure. It just checks what the value is. 1 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 2, 2020 Share Posted September 2, 2020 Great! I will try tomorrow and update you... Thanks @DennisHermannsen 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 3, 2020 Share Posted September 3, 2020 (edited) Can we use the field - Postcode instead of Phone Number Thanks @DennisHermannsen Edited September 3, 2020 by VirtualWorldGlobal 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 3, 2020 Share Posted September 3, 2020 Are you sure you also added the bottom piece of the hook? 1 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 3, 2020 Share Posted September 3, 2020 Working now - Can we use the field - Postcode instead of Phone Number, I have to use PostCode Thanks @DennisHermannsen 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 3, 2020 Share Posted September 3, 2020 You should be able to do it. Just note that it won't work if multiple users have the same postcode. Just change ->where('phonenumber', $username) to ->where('postcode', $username) 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 4, 2020 Share Posted September 4, 2020 (edited) Hi @DennisHermannsen Still unable to login, I also changed to default code you have provide in this post using Telephone. What should be the problem ? I want to use this Hook but failing drastically... Thanks Note: I am able to login properly with the email id used for the contact but not the mobile number unfortunately... Edited September 4, 2020 by VirtualWorldGlobal 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 4, 2020 Share Posted September 4, 2020 If you have multiple users with the same telephone number, you will get that error. You cannot in any way login if more than 1 account has the same value. It's impossible. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 4, 2020 Share Posted September 4, 2020 (edited) But I have different mobile numbers for both 1. Primary - ******3123 2. Contact - ******9000 But still unable to login, I am only using the mobile number not the Country Code + Mobile number Edited September 4, 2020 by VirtualWorldGlobal 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 4, 2020 Share Posted September 4, 2020 You should use country code. +123.456789 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 4, 2020 Share Posted September 4, 2020 Okay but then why the same error in POSTCODE , the country code was the reason why I thought about using Postcode where clients can use only their mobile number...Thanks It's only a value like 1. Primary - ******3123 2. Contact - ******9000 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 4, 2020 Share Posted September 4, 2020 It works just fine. This is an example with postcode instead of phonenumber: First, I enter an incorrect password - it denies the login. I then enter the correct password and gain access to the account. You need to enter the value that WHMCS stores in the database. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 4, 2020 Share Posted September 4, 2020 I will check database value and update you, I know that it's something at my end for sure, just trying to trouble shoot Thanks 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 4, 2020 Share Posted September 4, 2020 And also make sure that if any other user has the same value, the ValidateLogin call will not log you in. 0 Quote Link to comment Share on other sites More sharing options...
ManagedCloud-Hosting Posted September 4, 2020 Share Posted September 4, 2020 (edited) No there are no same values, I have checked, also with email address and same password I am able to login... It's only two values in both in post code and phone number fields 1. Primary - ******3123 2. Contact - ******9000 I removed all hooks from includes thinking that it may clash but no same problem, what can go wrong ? Edited September 4, 2020 by VirtualWorldGlobal 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.