1

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

kevin
  • 13,559
  • 30
  • 79
  • 104

3 Answers3

3

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

Community
  • 1
  • 1
1

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

Quincy
  • 1,923
  • 5
  • 27
  • 37
1

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.

ajcl
  • 381
  • 1
  • 11