• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Determine if a new password is alphanumeric

LEGEND ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

What is the best way to determine in coldfusion if a user has created an
alphanumeric password?


TOPICS
Advanced techniques

Views

1.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

<cfif REFind("[^a-zA-Z0-9]", passwordstring)>
-- code to do whatever with password if it is alphanumeric
<cfelse>
code to do whatever with password if it is not all alphanumeric
</cfif>

You can also use:

<cfif REFind("[[:alnum:]]", "passwordstring") >

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 26, 2006 Sep 26, 2006

Copy link to clipboard

Copied

thanks for the tip

<cfif #REfind("[^a-zA-Z0-9]", password)#>
<cfoutput>#password#</cfoutput>Password is alphanumeric
<cfelse>
<cfoutput>#password#</cfoutput>Password in not alphanumeric</cfif>

I took your advice and I cant seem to get it working. Is my syntax wrong?
Password is a form variable

the above code always produces password is not alphanumic after
entering 111aaa as password




"Abinidi" <webforumsuser@macromedia.com> wrote in message
news:efcco0$t8n$1@forums.macromedia.com...
> <cfif REFind("[^a-zA-Z0-9]", passwordstring)>
> -- code to do whatever with password
> <cfelse>
> code to reject users password
> </cfif>
>
> You can also use:
>
> <cfif REFind("[[:alnum:]]", "passwordstring") >
>
>
>


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2006 Sep 27, 2006

Copy link to clipboard

Copied

Can you clarify the requirement. Are you after passwords that are ONLY
alphanumeric (ie: must only contain a-z and 0-9, but no other characters),
or passwords that must have at least some alphanumeric characters in them
(so all alpha is no good, nor is all numeric).

The orginal regex matches any character that is not a-zA-Z0-9, so you have
your logic around the wrong way. If it DOES return a match, the pwd has a
non alpha-numeric character in it.

--
Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2006 Sep 27, 2006

Copy link to clipboard

Copied

Regular expressions are not my strong suit, but, don't you have that backwards?

If I do this.
<cfset x = REFind("[^a-zA-Z0-9]", "passwordstring")>
<cfdump var="#x#">
I get 0

If I do this:
<cfset x = REFind("[^a-zA-Z0-9]", "pas*swordstring")>
<cfdump var="#x#">
I get 4

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 27, 2006 Sep 27, 2006

Copy link to clipboard

Copied

Hi Adam, thanks for the note. Im trying to make sure that new users register
to use my web site with an alphanumeric password.

That is, their password must contain letters and numbers.


"Adam Cameron" <adam_junk@hotmail.com> wrote in message
news:5e0tx0nksh9s.54x4xll3pziy.dlg@40tude.net...
> Can you clarify the requirement. Are you after passwords that are ONLY
> alphanumeric (ie: must only contain a-z and 0-9, but no other characters),
> or passwords that must have at least some alphanumeric characters in them
> (so all alpha is no good, nor is all numeric).
>
> The orginal regex matches any character that is not a-zA-Z0-9, so you have
> your logic around the wrong way. If it DOES return a match, the pwd has a
> non alpha-numeric character in it.
>
> --
> Adam


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Sep 27, 2006 Sep 27, 2006

Copy link to clipboard

Copied

i am afraid Abidini did get it the other way around and confused oyu with that.

Correct sequence should be:

<cfif REFind("[^a-zA-Z0-9]", passwordstring)><!--- NO alphanumeric characters in passwordstring --->
.....
<cfelse><!--- passwordstring contains an alphanumeric character --->
....
</cfif>

if you are using <cfform> and <cfinput> tags in your form, then you can use CF validation on your password field:

<cfinput type="text" validate="regex" pattern="^[a-zA-Z0-9]*$" required="yes" message="your message to display if validation fails">

you must be using CFMX7 for this to work, though...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2006 Oct 03, 2006

Copy link to clipboard

Copied

BJ,

The regular expressions given (like "^[a-zA-Z0-9]$" are just ensuring that the string contains only letters or numbers, but not forcing the inclusion of at least one of each.

My thought was the string must either be:
<stuff 1><one letter><stuff 2><one digit><stuff 3>
or
<stuff 1><one digit><stuff 2><one letter><stuff 3>
where stuff 1, stuff 2, and stuff 3 are arbitrary (possibly empty) alphanumeric strings.

The regex for this is:
"^([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*|[a-zA-Z0-9]*[0-9][a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*)$"

The pipe "|" in the middle separates the two cases (the letter occurs before the number | the number occurs before the letter).

The ^ denotes the beginning of the string, and the $ denotes the end, so this RE will always return 1 if the password is OK, and zero otherwise.


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2006 Oct 04, 2006

Copy link to clipboard

Copied

LATEST
The regex for this is:

"^([a-zA-Z0-9]*[a-zA-Z][a-zA-Z0-9]*[0-9][a-zA-Z0-9]*|[a-zA-Z0-9]*[0-9][a-zA-Z0-9
]*[a-zA-Z][a-zA-Z0-9]*)$"


I would probably have done this like this:

<cfif refind("[a-z]"...) AND refind("[A-Z]"...) AND refind("[0-9]"...)...>

I'm sure they both work :-)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation