I need some help in php.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

I need some help in php....

https://code.sololearn.com/wWvSYAQ21gRr/?ref=app There is a Random Password Generator and strength checking code... There are many parts which could be improved. Can you tell me how multiple random passwords $pass1, $pass2, $pass3 could be putted in single loop of $pass???

20th Jan 2019, 11:22 AM
Taͣlhͪaͣ_ͥ
4 Answers
+ 1
You mean this ? $pass1=""; $pass2=""; $pass3=""; $plength=10; for($i=0;$i<$plength;$i++){ $pass3.=chr(rand(33,122)); $pass2.=chr(rand(33,122)); $pass1.=chr(rand(33,122)); }
20th Jan 2019, 11:37 AM
Niush
Niush - avatar
+ 2
Yes, somehow that is helpful. But exactly, if there is some way to make $pass along with loop of $n, where $n could be taken as 1, 2, 3... Some kinda for($n=0;$n<3;$n++){ $pass.$n=""; $plength=10; for($i=0;$i<$plength;$i++){ $pass.$n=chr(rand(33,122)); } } Is that possible somehow?
20th Jan 2019, 1:48 PM
Taͣlhͪaͣ_ͥ
+ 1
Ahh Okay there is a way: for($n=1;$n<=3;$n++){ ${"pass" . $n} = ""; $plength=10; for($i=0 ; $i<$plength ; $i++){ ${"pass" . $n} .= chr(rand(33,122)); } } i.e. use curly braces to wrap the variable name ${} PS: For the thing you are doing, I would prefer creating an array of n length.
20th Jan 2019, 2:51 PM
Niush
Niush - avatar
- 1
h eart's
3rd Feb 2019, 9:10 PM
Game Changed
Game Changed - avatar