Giter VIP home page Giter VIP logo

Comments (5)

toindev avatar toindev commented on May 30, 2024 2

Hi, just as an aside, "hard" password requirements are actually counter-productive, as a security measure.

For the purpose of checking the safety of a password, you would be better served by something like https://github.com/dropbox/zxcvbn

Nonetheless, have fun with regular expressions!

from magic-regexp.

didavid61202 avatar didavid61202 commented on May 30, 2024

You can do something like this:

const PASSWORD_RE = createRegExp(
  exactly('')
    .before(char.times.any().and(letter.lowercase))
    .before(char.times.any().and(letter.uppercase))
    .before(char.times.any().and(digit))
    .before(char.times.any().and(charIn('!@#$%^&*')))
    .and(letter.or(digit.or(charIn('!@#$%^&*'))).times.atLeast(8))
    .at.lineStart()
    .at.lineEnd()
)

charIn can just take all characters in one go as a string, but we do still missing Input helper that create custom range(s) to simplify more, ex: for regexp [b-t3-6]

from magic-regexp.

majkl-zumberi avatar majkl-zumberi commented on May 30, 2024

thanks @didavid61202 for your solution, i'll end up closing the issue
but let me first ask you to briefly explain how you ended up with this solution
why there's the need of exactly('')? and .at.lineStart() .at.lineEnd() what they do?

the documentation as i mentioned before isn't that clear

from magic-regexp.

leofcshen avatar leofcshen commented on May 30, 2024

@didavid61202
your solution create regex ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%\^&*])(?:[a-zA-Z]|(?:\d|[!@#$%\^&*])){8,}$
how to create more clear regex like ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%\^&*]).{8,}$

from magic-regexp.

zoeyzhao19 avatar zoeyzhao19 commented on May 30, 2024

@didavid61202 your solution create regex ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%\^&*])(?:[a-zA-Z]|(?:\d|[!@#$%\^&*])){8,}$ how to create more clear regex like ^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[!@#$%\^&*]).{8,}$

maybe

const regexp = createRegExp(
    exactly(
      exactly('')
        .before(char.times.any().and(letter.lowercase))
        .before(char.times.any().and(letter.uppercase))
        .before(char.times.any().and(digit))
        .before(char.times.any().and(charIn('!@#$%^&*'))),
      char
        .times.atLeast(8),
    )
      .at.lineStart()
      .at.lineEnd()
)

from magic-regexp.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.