<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 两条与密码验证相关的正则表达式问题</title>
	<atom:link href="http://iregex.org/blog/2-regex-problems-about-password-verification.html/feed" rel="self" type="application/rss+xml" />
	<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html</link>
	<description>原创、翻译、转载关于正则表达式的文章</description>
	<lastBuildDate>Fri, 30 Jul 2010 03:24:50 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
	<item>
		<title>By: rex</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-2116</link>
		<dc:creator>rex</dc:creator>
		<pubDate>Sun, 20 Dec 2009 15:48:11 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-2116</guid>
		<description>验证通过。</description>
		<content:encoded><![CDATA[<p>验证通过。</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 太阳照常升起</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-2110</link>
		<dc:creator>太阳照常升起</dc:creator>
		<pubDate>Sun, 20 Dec 2009 12:09:38 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-2110</guid>
		<description>第二题
^(?=(.*\d){4})(?=(.*[a-zA-Z]){6})[\da-zA-Z]{10}$</description>
		<content:encoded><![CDATA[<p>第二题<br />
^(?=(.*\d){4})(?=(.*[a-zA-Z]){6})[\da-zA-Z]{10}$</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: rex</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-2013</link>
		<dc:creator>rex</dc:creator>
		<pubDate>Thu, 10 Dec 2009 13:55:42 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-2013</guid>
		<description>呵呵，向vim正则高手致敬！我一般不怎么用vim正则，觉得语法太怪异:)</description>
		<content:encoded><![CDATA[<p>呵呵，向vim正则高手致敬！我一般不怎么用vim正则，觉得语法太怪异:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stonewang</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-2010</link>
		<dc:creator>stonewang</dc:creator>
		<pubDate>Thu, 10 Dec 2009 05:37:07 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-2010</guid>
		<description>第二道题的解法，手误了吧。

我用vim，第二道题的解法是：
^\(.*\d.*\d.*\d.*\d\)\@=\(.*[a-z].*[a-z].*[a-z].*[a-z].*[a-z].*[a-z]\)\@=[0-9a-z]\{10}$</description>
		<content:encoded><![CDATA[<p>第二道题的解法，手误了吧。</p>
<p>我用vim，第二道题的解法是：<br />
^\(.*\d.*\d.*\d.*\d\)\@=\(.*[a-z].*[a-z].*[a-z].*[a-z].*[a-z].*[a-z]\)\@=[0-9a-z]\{10}$</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cnhacktnt</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-1723</link>
		<dc:creator>cnhacktnt</dc:creator>
		<pubDate>Wed, 28 Oct 2009 15:51:06 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-1723</guid>
		<description>我的方法漏掉了一个环节，有逻辑上的漏洞(漏掉了全是字母和[@%&amp;]这种情况），作如下修改：

/^(?![0-9a-z]{8,16}$&#124;[a-z@%&amp;]{8,16}$)[a-z0-9@%&amp;]{8,16}$/i

感谢 rex 及 rex 朋友的指正。
很多时候，需要考虑多个条件的正则确实会让人发晕呵呵，这个时候，完整的测试数据覆盖就显得很重要:-)</description>
		<content:encoded><![CDATA[<p>我的方法漏掉了一个环节，有逻辑上的漏洞(漏掉了全是字母和[@%&amp;]这种情况），作如下修改：</p>
<p>/^(?![0-9a-z]{8,16}$|[a-z@%&amp;]{8,16}$)[a-z0-9@%&amp;]{8,16}$/i</p>
<p>感谢 rex 及 rex 朋友的指正。<br />
很多时候，需要考虑多个条件的正则确实会让人发晕呵呵，这个时候，完整的测试数据覆盖就显得很重要:-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: chunzi</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-1716</link>
		<dc:creator>chunzi</dc:creator>
		<pubDate>Sun, 25 Oct 2009 13:41:13 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-1716</guid>
		<description>如果用了 * + 就会被 charlie 认为：这个人显然不认识 never 这个英文单词！Slava 就是个活生生的例子。不过我们的工作写出来的 regex 普遍需要求值百万次/天以上，所以很在乎性能。cnhacktnt 显然抱有极高的专业素养。但这里对密码验证的情况，显然不是性能瓶颈，应该无所谓，问题的提出也多在探讨可能性。实践中最好分开判断，增加可读性：一行代码仅完成一个简单逻辑。更直观，也更易维护。:-)</description>
		<content:encoded><![CDATA[<p>如果用了 * + 就会被 charlie 认为：这个人显然不认识 never 这个英文单词！Slava 就是个活生生的例子。不过我们的工作写出来的 regex 普遍需要求值百万次/天以上，所以很在乎性能。cnhacktnt 显然抱有极高的专业素养。但这里对密码验证的情况，显然不是性能瓶颈，应该无所谓，问题的提出也多在探讨可能性。实践中最好分开判断，增加可读性：一行代码仅完成一个简单逻辑。更直观，也更易维护。:-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cnhacktnt</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-1712</link>
		<dc:creator>cnhacktnt</dc:creator>
		<pubDate>Fri, 23 Oct 2009 09:17:22 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-1712</guid>
		<description>我的工作就是个例子，我的工作中是不允许出现 *, + 的 :-)</description>
		<content:encoded><![CDATA[<p>我的工作就是个例子，我的工作中是不允许出现 *, + 的 <img src='http://iregex.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Yurii</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-1689</link>
		<dc:creator>Yurii</dc:creator>
		<pubDate>Sat, 17 Oct 2009 22:49:54 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-1689</guid>
		<description>@cnhacktnt
好，你下面改的更好！
如果可以的话，能给我一个“抵触贪婪模式”的实际例子吗？算是帮个忙
谢谢</description>
		<content:encoded><![CDATA[<p>@cnhacktnt<br />
好，你下面改的更好！<br />
如果可以的话，能给我一个“抵触贪婪模式”的实际例子吗？算是帮个忙<br />
谢谢</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cnhacktnt</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-1685</link>
		<dc:creator>cnhacktnt</dc:creator>
		<pubDate>Sat, 17 Oct 2009 12:21:03 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-1685</guid>
		<description>另外，我第一篇回复中的&quot;麻烦&quot;没有恶意，sorry ：-）</description>
		<content:encoded><![CDATA[<p>另外，我第一篇回复中的&#8221;麻烦&#8221;没有恶意，sorry ：-）</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cnhacktnt</title>
		<link>http://iregex.org/blog/2-regex-problems-about-password-verification.html/comment-page-1#comment-1684</link>
		<dc:creator>cnhacktnt</dc:creator>
		<pubDate>Sat, 17 Oct 2009 12:19:16 +0000</pubDate>
		<guid isPermaLink="false">http://iregex.org/?p=68#comment-1684</guid>
		<description>那两个条件我是用 &#124; 来分隔的阿，在(?!)里加 &#124; 不需要你再用括号，nest parenthesis 会增加额外开销。另外我把这个&quot;密码不少于8位&quot;看走眼了呵呵,这是我的失误。
正则是随手写的，没有经过验证呵呵。
重新改写：

/^(?![0-9a-z]*$&#124;[@%&amp;]*$)[a-z0-9@%&amp;]{8}/i

最后的 $ 是可以不要的。
另外可能由于工作的关系，对于贪婪模式，个人非常抵触，如果这个正则用于实际项目的密码验证，大多数情况下用户提交的密码应该是有个范围限定的，比如8-16位。所以能有限定，还是把限定加上：

/^(?![0-9a-z]{8,16}$&#124;[@%&amp;]{8,16}$)[a-z0-9@%&amp;]{8,16}$/i

:-)</description>
		<content:encoded><![CDATA[<p>那两个条件我是用 | 来分隔的阿，在(?!)里加 | 不需要你再用括号，nest parenthesis 会增加额外开销。另外我把这个&#8221;密码不少于8位&#8221;看走眼了呵呵,这是我的失误。<br />
正则是随手写的，没有经过验证呵呵。<br />
重新改写：</p>
<p>/^(?![0-9a-z]*$|[@%&amp;]*$)[a-z0-9@%&amp;]{8}/i</p>
<p>最后的 $ 是可以不要的。<br />
另外可能由于工作的关系，对于贪婪模式，个人非常抵触，如果这个正则用于实际项目的密码验证，大多数情况下用户提交的密码应该是有个范围限定的，比如8-16位。所以能有限定，还是把限定加上：</p>
<p>/^(?![0-9a-z]{8,16}$|[@%&amp;]{8,16}$)[a-z0-9@%&amp;]{8,16}$/i</p>
<p> <img src='http://iregex.org/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>
