Skip to main content

Posts

Showing posts from November, 2020

How to generate a valid random mail using Jquery Javascript?

How to generate a valid random mail using Jquery or Javascript In this tutorial we will learn how to generate a random unique email address using Pure Javascript. Use below code it will return a function generateEmail() { var allchars = 'abcdefghijklmnopqrstuvwxyz1234567890'; var emailLength = 15; var string = ''; for(var i=0; i<emailLength; i++){     string += allchars[Math.floor(Math.random() * allchars.length)]; } string = string + '@gmail.com'; return string; } var newEmail = generateEmail(); alert(newEmail); Code Explain: We have created "allchars" variable that contains all possible characters that our function will use, if you want to remove numbers from it or add capital letters , you can edit this string. Then we have defined "emailLength" variable , You can change length of email according tou your requirement. Then we are looping until the length and generating random string using Math functions. Finally we are adding postfix em...

Cakephp 4: How to convert string to hash password

CakePHP 4: How to convert string to hash password This tutorial works for both CakePHP  3 and CakePHP 4. Sometimes we want to add custom login or wants to add custom login  or we want client side password hashing using cakephp Hash functions , so for that we need to use DefaultPasswordHasher which provides inbuilt functionality to check two passwords , compare it or convert a string to Hash etc. To use password hashing please follow below steps:- Step 1 Call a class after the namespace. use Cake\Auth\DefaultPasswordHasher; Step 2 Now we can use functions of DefaultPasswordHasher().  Use below code to change a simple string password to a secure string and its non reversible . $password = "My Password String"; $hasher = new DefaultPasswordHasher(); $newPassword = $hasher->hash($password);  Now if you print $newPassword to test its working or not, then you will get it an unique hash everytime on refresh, because CakePHP use different mechanism to handle hash that is ...