English 中文(简体)
• 如何创造安全通行证?
原标题:How To Generate (Somewhat) Secure Passwords in PHP?
  • 时间:2009-11-17 19:15:19
  •  标签:
  • php

我试图履行能够产生随机密码的职能,必须符合以下要求:

  • Between 8 & 14 characters
  • Contain a least one of the following: lowercase letter, uppercase letter, punctuation, and number

实现这一目标的最佳途径是什么,这样,这一职能能够产生符合上述要求的所有可能的密码?

最佳回答
  1. Generate a lowercase letter, uppercase letter, punctuation symbol and number, so you now have 4 characters.
  2. Generate 4-10 random characters from the entire set of above.
  3. Shuffle the resulting string. In PHP you can use str_shuffle.

然而,应该指出,如果你重新产生随机特性,迫使每个密码至少有一个编号/图象等,实际上没有任何保障。 事实上,你可以说,这不太安全,因为它实际上限制了你的密码选择。

问题回答

http://www.google.com/search?q=php+password+generator” rel=“nofollow noretinger”>PHP Password Plant(包括来源)。 其中几个国家有能力从你提到的品级中具体规定最低要求。

其中大部分依靠功能。 这有一些安全风险,但可能为你们所接受。 也可以用mt_rand(功能,以方便随机。

如果你真的需要获得一个良好的随机来源,那么你需要把手法上打上灯(即:/dev/random in linux or the ,<a 物体载于Windows)。

略微的怀疑做法:

Generate a random number between 8 and 14
generate a completely random string of characters that is that long
Check it against a regular expression that defines the lowercase/uppercase/etc requirement If it fails, try again.

简言之,应简明扼要。 与此类似,只是为了纠正长度,随机抽取高压,插入随机校准:

sha1(microtime() . rand(0,100))

我应该指出,我看到,在某种地方,这种口号的形成确实是聪明的,可能比这好,但可以回顾到什么地方。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...