C语言的密码复杂度
您好,我正在实习,我的公司告诉我必须使用 C 语言实现密码复杂性。密码必须是字母数字(例如h#ll0)。由于我是 C 新手,我发现有些困难。我用谷歌搜索“C 中的密码复杂性”,但没有运气。有人可以给我一些示例或解释我如何以编程方式执行此操作。
预先非常感谢
凯文
Hi I'm on my internship and my company told me that I've to implement password complexity using C language. The password must be Alpha numeric (eg h#ll0). Since I'm new to C , I found some difficulty. I google "password complexity in C " but no luck there. Can someone gave me some sample or explain me how to do it programmatically.
Thanks a lot in advance
Kevin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
更好的 Google 术语是“强密码”:
http://en.wikipedia.org/wiki/Password_strength
但是您会发现的大多数文章都不是针对 C 语言的,并且他们可能会建议使用正则表达式。
按照其他人的建议编写自己的低级代码来进行检查可能不会太难。这将为您省去生成对某些 C 语言正则表达式库的依赖以供使用的麻烦。但是,使用正则表达式有一个优点,因为这意味着非 C 程序员将有更好的机会在以后更新规则,并且可能会降低引导错误的可能性。这取决于您的具体情况。
(此外,如果您的 C 代码的其他部分需要正则表达式,那么您可能需要链接其中的一个,并且“免费”获得它...)
无论如何,这个 StackOverflow 问题都有一个 regex.h 教程的链接,并且将来可能会添加更多内容:
C - 清晰的regex.h使用教程
A better Google term would be "strong password":
http://en.wikipedia.org/wiki/Password_strength
But most of the articles you will find will not be for the C language, and they will probably suggest using a regular expression.
It would probably not be too hard to write your own low-level code to do the check as others have suggested. That would save you the trouble of generating a dependency on some C-language regular expression library to use. However, there is an advantage in using a regular expression because it means that non-C programmers would have a better chance at updating the rule at a later date, and it may make errors less likely to boot. It depends on your particular situation.
(Also, if other parts of your C code need regular expressions, then linking one in might be something you're going to need to do anyway and you'd get it "for free"...)
In any case, this StackOverflow question has a link to a regex.h tutorial, and more may be added to it in the future:
C - pellucid regex.h use tutorial
您没有提供足够的信息。我认为密码复杂性指的是密码强度。
我不从事为某人编写代码的业务,但如果您想要做的是确定密码是否同时包含字母和数字,则长度至少为 n 个字符等等,C 有一些函数可以做到这一点。测试时会想到 isalnum()、isdigit() 和 isalpha()。这些都返回非零值来指示 true。
就速度而言,C 本身很快,但请记住,无需解析整个密码 - 您所需要的只是函数在某个时刻返回一个非零值。 (所有这些函数都按字符解析;C 字符串是 char 数组。)
http:// icecube.wisc.edu/~dglo/c_class/charfunc.html 这是关于字符解析函数的一个很好的小参考。
You don't provide enough information. By password complexity I assume you mean password strength.
I'm not in the business of writing code for someone, but if what you're looking to do is determine whether or not a password contains both a letter and a number, is at least n characters long, etc., C has functions you can do this with. isalnum(), isdigit(), and isalpha() come to mind for testing. These all return nonzero values to indicate true.
In terms of speed, C is fast on its own but remember with these that there is no need to parse the entire password -- all you need is for the function to return a nonzero value at some point. (All of these functions parse by character; C strings are char arrays.)
http://icecube.wisc.edu/~dglo/c_class/charfunc.html This is a good little reference for character parsing functions.
这取决于密码的编码方式,您可能需要 ASCII 字符图表或 unicode 字符图表。对于输入密码中的每个字符,将其分为数字、大写字母、小写字母或特殊字符等组。
以下是表格的链接:
http://www.asciitable.com/
http://www.tamasoft.co.jp/en/general-info/unicode.html
It depends on how the password is encoded, you may need an ASCII character chart or a unicode character chart. For each character in the input password, categorize it into groups number, uppercase letter, lowercase letter or special characters and so on.
here are the links to the tables:
http://www.asciitable.com/
http://www.tamasoft.co.jp/en/general-info/unicode.html