-2

I've seen question online but most of them were not classified as accepted answers and the rest don't work.

I'm trying to make a regular expression in asp.net for a password that contains at least 8 characters, at least one upper case character, at least one lower case character, at least one number, and at least one special character.

  • You can find lots of examples here http://regexlib.com/Search.aspx?k=password&AspxAutoDetectCookieSupport=1 – hardkoded May 31 '17 at 12:36
  • There is a duplicate question already with this specific title. On the other hand, why are you trying to force the use of *WEAK* passwords? Why don't you let me use a long, secure passphrase ? 8 characters is [too damn short](https://blog.codinghorror.com/your-password-is-too-damn-short/) – Panagiotis Kanavos May 31 '17 at 12:42
  • You should check Jeff Attwood's [Password rules are Bu*****it](https://blog.codinghorror.com/password-rules-are-bullshit/). – Panagiotis Kanavos May 31 '17 at 12:46

2 Answers2

0

You can use this expression

^(?=.?[A-Z])(?=.?[a-z])(?=.?[0-9])(?=.?[#?!@$%^&*-]).{8,}$

Rutu
  • 11
  • 3
0

Try this:

^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[~!@#$%^&*+]).{8,}$

Demo: https://regex101.com/r/hmHOzY/1

You may probably want to extend the special characters list.

Dmitry Egorov
  • 9,337
  • 3
  • 23
  • 39