Laravel password strength validation - laravel

Is there any better way to validate password, I know below
'password' => 'required|
min:6|
regex:/^.(?=.{3,})(?=.[a-zA-Z])(?=.[0-9])(?=.[\d\x])(?=.[!$#%]).$/|
confirmed',

Here is a much better solution from the Laravel Docs:
use Illuminate\Validation\Rules\Password;
// Require at least 8 characters...
Password::min(8)
// Require at least one letter...
Password::min(8)->letters()
// Require at least one uppercase and one lowercase letter...
Password::min(8)->mixedCase()
// Require at least one number...
Password::min(8)->numbers()
// Require at least one symbol...
Password::min(8)->symbols()

You can try Laravel docs as well
Neither Just try below,
'password' => [
'required',
'string',
'min:10', // must be at least 10 characters in length
'regex:/[a-z]/', // must contain at least one lowercase letter
'regex:/[A-Z]/', // must contain at least one uppercase letter
'regex:/[0-9]/', // must contain at least one digit
'regex:/[#$!%*#?&]/', // must contain a special character
],

Related

How to add Regular Expression in Javascript?

I have a Requirement for password pattern as below
=> Password Should contain atleast 1 upper case character
=> Password Should contain atleast 1 lower case character
=> Password Should contain atleast 1 number
=> Password Should contain atleast 1 special character !#$&

How to disallow repeated numbers in telephone field like 1111111 or 222222

I am using contact form 7 and want to disallow users to enter repeated numbers like 1111111 or 2222222 in phone field.
I am using below code to enter only 10 digits. Can anyone help me with what I should change or add in this to work.
// define the wpcf7_is_tel callback<br>
function custom_filter_wpcf7_is_tel( $result, $tel ) {<br>
$result = preg_match( '/^\(?\+?([0-9]{0})?\)?[-\. ]?(\d{10})$/', $tel );<br>
return $result; <br>
}<br>
add_filter( 'wpcf7_is_tel', 'custom_filter_wpcf7_is_tel', 10, 2 );
First of all, [0-9]{0} looks like a typo as this pattern matches nothing, an empty string. You probably wanted to match an optional area code, three digits. So, use \d{3} if you meant that.
Next, to disallow same digits within those you match with \d{10}, you simply need to re-write it as (?!(\d)\1{9})\d{10}.
Bearing in mind what was said above, the solution is
function custom_filter_wpcf7_is_tel( $result, $tel ) {<br>
return preg_match('/^\(?\+?(?:\d{3})?\)?[-. ]?(?!(\d)\1{9})\d{10}$/', $tel );<br>
}
See the regex demo.

Ruby: How to generate strings of variable bits length with only alphanumeric characters?

I am trying to solve the following problem using Ruby:
I have a requirement to generate strings with variable bits length which contain only alphanumeric characters.
Here is what I have already found:
Digest::SHA2.new(bitlen = 256).to_s
# => "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
It does exactly what I need, but it accepts only 256, 384, and 512 as bitlen.
Does anybody aware of any alternatives?
Thanks in advance.
Update
One byte = collection of 8 bits.
Every alphanumeric character occupies 1 byte according to String#bytesize.
('a'..'z').chain('A'..'Z').chain('0'..'9').map(&:bytesize).uniq
# => [1]
Based on the facts mentioned above, we can suppose that
SecureRandom.alphanumeric(1) generates an alphanumeric string with 8 bits length.
SecureRandom.alphanumeric(2) generates an alphanumeric string with 16 bits length.
SecureRandom.alphanumeric(3) generates an alphanumeric string with 24 bits length.
And so on...
As a result, #anothermh's answer can be considered as an acceptable solution.
Use SecureRandom.
First, make sure you require it:
require 'securerandom'
Then you can generate values:
SecureRandom.alphanumeric(10)
=> "hxYolwzk0P"
Change 10 to whatever length you require.
It's worth pointing out that the example you used was returning not alphanumeric but hexadecimal values. If you specifically require hex then you can use:
SecureRandom.hex(10)
=> "470eb1d8daebacd20920"

The plus sign is deleted when importing to the xls file

Laravel version 5.4
Expected behaviour
Actual behaviour
Steps to reproduce the behaviour
$sheet->setColumnFormat(array(
'A' => '#'
));
foreach ($order_details as $key => $detail) {
$sheet->appendRow([(string)$detail->model->id_supplier, $detail->model->mintitle, $detail->qty, $detail->price, $detail->qty * $detail->price,]);
$sheet->setHeight($sheet->getHighestRow(), 45);
}
How to import a number with a plus sign?
if that is microsoft excel, or some similar app; then it is not in your code, excel treats the +digit as a positive digit, and hence it removes the +, happens with the zeroes as well, try to include '' wrapper around your value to convert it to string and to prevent excel from doing so.
It happens because the number you expect was a positive digit(+49983), if you reproduce the number with + sign, it removes + sign while displaying in excel.,
To check open a new excel and try to add +49983 and move to next column, the + will automatically gone, because of the positive digit.

Extracting numbers and slashes from a string

I have the following string
Policy 023203232/02/05 saved successfully
And I need to extract 023203232/02/05 from the above string and I have written the following code
puts a[/\d+\/\d+\/\d+/]
And it works fine. But If the number increases with the slashes like, 023203232/02/05/06 I have to include one more \d+ but I don't know how many slashes and number would repeat this way, So any one can suggest me to write some generic solution
If string is
Policy 023203232/02/05 saved successfully
Then
023203232/02/05
If string is
Policy 023203232/02/05/06 saved successfully
Then
023203232/02/05/06
If string is
Policy 023203232/02/05/06/08 saved successfully
Then
023203232/02/05/06/08
How to write such a generic regular expression?
Assuming contiguous digits and slashes (i.e. no spaces in between), this should work:
a.scan(/\d+\/?/).join
This regex should be what you're looking for :
/(\d+\/?)+/
It means :
At least one pattern of :
at least one digit
possibly followed by a /
It should be a bit more robust than the other answers :
"Policy 023203232/02/05/06/08 saved successfully"[/(\d+\/?)+/]
# => "023203232/02/05/06/08"
"Policy 023203232/02/05/07/3434343/56 saved successfully 09/56/32"[/(\d+\/?)+/]
# => "023203232/02/05/07/3434343/56"
"Policy // // 023203232/02/05/07/3434343/56 saved successfully 09/56/32"[/(\d+\/?)+/]
# => "023203232/02/05/07/3434343/56"
If you want to make sure that the number is right after 'Policy ' but don't want to have 'Policy ' inside your match, you can use a positive look-behind :
/(?<=Policy )(\d+\/?)+/
Here in action :
"2017/03/31 Policy 023203232/02/05/07/3434343/56 saved successfully"[/(?<=Policy )(\d+\/?)+/]
# => "023203232/02/05/07/3434343/56"
This one looks for a serie of digits or slashes:
str = "Policy 023203232/02/05/07/3434343/56 saved successfully 09/56/3"
p str.match(/[0-9\/]+/)[0] # => "023203232/02/05/07/3434343/56"

Resources