Comments (5)
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.
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.
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.
@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.
@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)
- $ Character gets escaped twice HOT 2
- `createRegExp` not sanitising strings (in type) HOT 1
- Very low contrast
- Incorrect open graph image HOT 1
- 500 - If you want to use `GithubLink` component, you must specify: `owner`, `repo` and `branch`.
- No "exports" main defined in ....\.pnpm\[email protected]\node_modules\estree-walker\package.json HOT 3
- Lazy quantifier HOT 1
- not.word is not defined HOT 1
- Why is `MagicRegExpMatchArray` typed with `string | undefined`? HOT 3
- Infer the literals used in the type of the groups HOT 10
- Allow for custom regex, and clarifying the usage of `anyOf()` HOT 7
- Library blocks Typescript compilation HOT 2
- Action Required: Fix Renovate Configuration
- Documentation site is down HOT 1
- Can I rework docs using Nuxt UI Pro HOT 4
- Maige Usage
- Support match everything in preset inputs
- `Predefined Input can not be assigned to InputSource` when using with TypeScript < 4.7 HOT 6
- performance testing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from magic-regexp.