CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Random

Print topic Send  topic

Author Message
2Code

Posts: 24
Posted: 06/11/2014, 1:27 PM

I have this code working to generate random password however I want to make it numbers only and not letters

function randompassword($length){
srand((double)microtime()*1000000);

$vowels = array("a", "e", "i", "o", "u");
$cons = array("b", "c", "d", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "u", "v", "w", "tr",
"cr", "br", "fr", "th", "dr", "ch", "ph", "wr", "st", "sp", "sw", "pr", "sl", "cl");

$num_vowels = count($vowels);
$num_cons = count($cons);

for($i = 0; $i < $length; $i++){
$password = $cons[rand(0, $num_cons - 1)] . $vowels[rand(0, $num_vowels - 1)];
}
return substr($password, 0, $length);
}


View profile  Send private message
MichaelMcDonald

Posts: 639
Posted: 06/12/2014, 1:38 PM

What happens if you replace the characters in your array with numbers?
_________________
Central Coast, NSW, Australia.

View profile  Send private message
eratech


Posts: 513
Posted: 06/12/2014, 10:28 PM

If all you want is numbers, then you could just generate a random number:

(code NOT tested in any way)

function randompassword() {   
$password = rand(1000000,9999999);   
return $password;   
} 

This should get a random integer between 1,000,000 and 9,999,999. Increase the min and max values to get the right length.

see http://www.php.net/manual/en/function.rand.php

Cheers

Eric

_________________
CCS 3/4/5 ASP Classic, VB.NET, PHP
Melbourne, Victoria, Australia
View profile  Send private message
MichaelMcDonald

Posts: 639
Posted: 06/13/2014, 3:26 AM

I see this type of question a lot in posts.

A good solution in so many ways, but doesn't meet relevance due to complexity and if novice respond to the posts with best intentions can bloat the solution and create dead ends and lack of integration and reuse.

Makes me wonder where good PHP training materials for simple applications are.

I in this case even overlooked the basics while Eratech hit the nail on the head.
_________________
Central Coast, NSW, Australia.

View profile  Send private message
2Code

Posts: 24
Posted: 06/13/2014, 8:05 AM

Quote MichaelMcDonald:
I see this type of question a lot in posts.

A good solution in so many ways, but doesn't meet relevance due to complexity and if novice respond to the posts with best intentions can bloat the solution and create dead ends and lack of integration and reuse.

Makes me wonder where good PHP training materials for simple applications are.

I in this case even overlooked the basics while Eratech hit the nail on the head.


And I see this post all the time in fact its not that the basics need to be re learned its when developers build in other ide and code charge doesn't recognize php code for instance in code trace in the latest ZS with Apache the latest version of ccs php is using depreciated code and some custom code that should work don't . so before you assume know the facts.
View profile  Send private message
MichaelMcDonald

Posts: 639
Posted: 06/13/2014, 3:39 PM

Seriously, the posts are riddled with this type of question and it might have something to do with the layout of the forum.
_________________
Central Coast, NSW, Australia.

View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright 2003-2004 by UltraApps.com  and YesSoftware, Inc.