Skip to content

Commit 3f5bfcd

Browse files
committed
docs: 📝 Add documentation about the preset format
1 parent 23ff75a commit 3f5bfcd

File tree

3 files changed

+83
-46
lines changed

3 files changed

+83
-46
lines changed

README.md

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,42 @@ The brains behind Cloverleaf
2424
## siteData
2525
**Returns**: <code>object</code> - Data for preset sites
2626

27+
Schema (How the JSON is structured):
28+
29+
```json
30+
"App Name": {
31+
"alias": "Real app", // Makes passwords as if this was the app name
32+
"minLength": 4, // The minimum length of a password allowed on this preset (inclusive)
33+
"maxLength": 512, // The maximum length of a password allowed on this preset (inclusive)
34+
"chars": "abc123", // The password will be made out of a random selection of these characters.
35+
"deprecated": false, // Used to hide presets
36+
"regex": "^(?!.*(.)\\1{2,}).+", // A regex the password must match. This one disallows repetitions of 3 or more of the same character
37+
"requirements": ["cap", "low", "num", "special"], // Passwords must have at least one of these character types
38+
}
39+
```
40+
41+
The only requirements for a valid preset is an alias or minimum length, the rest is optional.
42+
2743

2844
# Contributing
2945

30-
`
31-
pnpm i
32-
`
46+
## Creating a new preset
47+
Making a new preset is pretty easy. All data for presets is kept in [sites.json](/data/sites.json). There's a json schema that describes what is needed but the tl;dr is this:
48+
49+
Add a new key in the JSON object (in alphabetical order) with the name of the site/app you're making a preset for.
50+
51+
### Working out a site's restrictions
52+
#### Character restrictions
53+
A good first test is pasting this in and seeing if it's upset about any characters:
54+
55+
``0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~``
56+
57+
If it is then you need to work out which it doesn't like. This can take a long time but can be sped up if you use a kind of binary search and half the string until you can pinpoint what is causing an issue.
58+
59+
#### Length restrictions
60+
You also then need to work out if there are any minimum and maximum lengths. The first is easily discovered by attempting to use just "a" or something like that. For the maximum length I generally try a string that's over 512 characters (the default max for cloverleaf passwords).
61+
62+
#### Other restrictions
63+
Some sites have basic restrictions such as "must have a special character" or "must use a number and a capital". For these we use the "requirements" key and an array or required character types ("cap", "low", "num" and "special")
64+
65+
Some websites disallow repeated characters (EG. `aaa`) or common phrases like `qwerty`, `abc` or `123`. If a site has these restrictions you will need to add a regex.

data/sites_schema.json

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,52 @@
11
{
2-
"$schema": "http://json-schema.org/draft-07/schema#",
3-
"type": "object",
4-
"patternProperties": {
5-
"^[^\"\/\\\n]+$": {
6-
"properties": {
7-
"alias": {
8-
"type": "string"
9-
},
10-
"chars": {
11-
"type": "string",
12-
"pattern": "^(?!.*(.).*\\1).+$"
13-
},
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"patternProperties": {
5+
"^[^\"\/\\\n]+$": {
6+
"properties": {
7+
"alias": {
8+
"type": "string",
9+
"description": "Used to redirect internally (YouTube passwords should be the same as Google passwords)"
10+
},
11+
"chars": {
12+
"type": "string",
13+
"pattern": "^(?!.*(.).*\\1).+$"
14+
},
1415
"deprecated": {
1516
"type": "boolean"
1617
},
17-
"maxLength": {
18-
"minimum": 1,
19-
"type": "integer"
20-
},
21-
"minLength": {
22-
"minimum": 1,
23-
"type": "integer",
24-
"description": "The minimum length of a password allowed on this preset (inclusive)"
25-
},
26-
"regex": {
27-
"type": "string",
28-
"format": "regex"
29-
},
30-
"requirements": {
31-
"type": "array",
32-
"minItems": 1,
33-
"maxItems": 4,
34-
"uniqueItems": true,
35-
"items": {
36-
"type": "string",
37-
"enum": ["cap", "low", "num", "special"]
38-
}
39-
}
40-
},
41-
"anyOf": [
42-
{ "required": ["alias"]},
43-
{ "required": ["minLength"]}
18+
"maxLength": {
19+
"minimum": 1,
20+
"type": "integer",
21+
"description": "The maximum length of a password allowed on this preset (inclusive)"
22+
},
23+
"minLength": {
24+
"minimum": 1,
25+
"type": "integer",
26+
"description": "The minimum length of a password allowed on this preset (inclusive)"
27+
},
28+
"regex": {
29+
"type": "string",
30+
"format": "regex",
31+
"description": "A regex that the password will be tested against. If it returns true, the password can be used."
32+
},
33+
"requirements": {
34+
"type": "array",
35+
"minItems": 1,
36+
"maxItems": 4,
37+
"uniqueItems": true,
38+
"items": {
39+
"type": "string",
40+
"enum": ["cap", "low", "num", "special"]
41+
}
42+
}
43+
},
44+
"anyOf": [
45+
{ "required": ["alias"]},
46+
{ "required": ["minLength"]}
4447
],
45-
"type": "object",
46-
"additionalProperties": false
47-
}
48-
}
48+
"type": "object",
49+
"additionalProperties": false
50+
}
51+
}
4952
}

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export function generate (appName, masterPass, presetToggle = false, length = de
107107

108108
}
109109

110+
// Correct the desired password length to fit a preset
110111
if (!(minLength <= length && length <= maxLength)) {
111112
// if the length is invalid
112113
if (length > maxLength) {

0 commit comments

Comments
 (0)