Skip to content

Commit a6a14a0

Browse files
authored
Merge pull request #43 from CodeDead/feature/create-vault-double-input
Require double key entry when creating a vault
2 parents a2105c7 + d95632f commit a6a14a0

File tree

4 files changed

+60
-25
lines changed

4 files changed

+60
-25
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"@emotion/styled": "^11.10.5",
88
"@fontsource/roboto": "^4.5.8",
99
"@mui/icons-material": "^5.11.0",
10-
"@mui/material": "^5.11.2",
10+
"@mui/material": "^5.11.3",
1111
"@shopify/react-web-worker": "^5.0.6",
1212
"@tauri-apps/api": "^1.2.0",
1313
"@testing-library/jest-dom": "^5.16.5",

src/components/EncryptionKeyDialog/index.jsx

Lines changed: 48 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,24 @@ import DialogContent from '@mui/material/DialogContent';
55
import DialogTitle from '@mui/material/DialogTitle';
66
import DialogActions from '@mui/material/DialogActions';
77
import Button from '@mui/material/Button';
8+
import Grid from '@mui/material/Grid';
89
import { MainContext } from '../../contexts/MainContextProvider';
910

10-
const EncryptionKeyDialog = ({ open, onAccept, onClose }) => {
11+
const EncryptionKeyDialog = ({
12+
open, onAccept, onClose, verify,
13+
}) => {
1114
const [state] = useContext(MainContext);
1215
const language = state.languages[state.languageIndex];
1316

1417
const [key, setKey] = useState('');
18+
const [key2, setKey2] = useState('');
1519

1620
/**
1721
* Close the dialog
1822
*/
1923
const handleClose = () => {
2024
setKey('');
25+
setKey2('');
2126
if (onClose) {
2227
onClose();
2328
}
@@ -30,6 +35,9 @@ const EncryptionKeyDialog = ({ open, onAccept, onClose }) => {
3035
if (key.length === 0) {
3136
return;
3237
}
38+
if (verify && key !== key2) {
39+
return;
40+
}
3341
if (onAccept) {
3442
onAccept(key);
3543
}
@@ -44,6 +52,14 @@ const EncryptionKeyDialog = ({ open, onAccept, onClose }) => {
4452
setKey(e.target.value);
4553
};
4654

55+
/**
56+
* Change the verification key value
57+
* @param e The event argument
58+
*/
59+
const handleVerifyChange = (e) => {
60+
setKey2(e.target.value);
61+
};
62+
4763
/**
4864
* Handle the key up event
4965
* @param e The event argument
@@ -64,18 +80,36 @@ const EncryptionKeyDialog = ({ open, onAccept, onClose }) => {
6480
{language.decryptionKey}
6581
</DialogTitle>
6682
<DialogContent>
67-
<TextField
68-
sx={{ mt: 2 }}
69-
value={key}
70-
type="password"
71-
error={key.length === 0}
72-
label={language.decryptionKey}
73-
onChange={handleChange}
74-
onKeyUp={handleKeyUp}
75-
autoComplete="off"
76-
variant="outlined"
77-
fullWidth
78-
/>
83+
<Grid container spacing={2} sx={{ mt: 2 }}>
84+
<Grid item xs={12} md={12} lg={12}>
85+
<TextField
86+
value={key}
87+
type="password"
88+
error={key.length === 0 || (verify && key !== key2)}
89+
label={language.decryptionKey}
90+
onChange={handleChange}
91+
onKeyUp={handleKeyUp}
92+
autoComplete="off"
93+
variant="outlined"
94+
fullWidth
95+
/>
96+
</Grid>
97+
{verify ? (
98+
<Grid item xs={12} md={12} lg={12}>
99+
<TextField
100+
value={key2}
101+
type="password"
102+
error={key2.length === 0 || (verify && key !== key2)}
103+
label={language.decryptionKey}
104+
onChange={handleVerifyChange}
105+
onKeyUp={handleKeyUp}
106+
autoComplete="off"
107+
variant="outlined"
108+
fullWidth
109+
/>
110+
</Grid>
111+
) : null}
112+
</Grid>
79113
</DialogContent>
80114
<DialogActions>
81115
<Button onClick={handleClose}>
@@ -84,7 +118,7 @@ const EncryptionKeyDialog = ({ open, onAccept, onClose }) => {
84118
<Button
85119
onClick={accept}
86120
autoFocus
87-
disabled={key.length === 0}
121+
disabled={key.length === 0 || (verify && key !== key2)}
88122
>
89123
{language.ok}
90124
</Button>

src/routes/Vault/index.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ const Vault = () => {
414414
</Box>
415415
<EncryptionKeyDialog
416416
open={keyDialogOpen}
417+
verify={keyAction === 'create'}
417418
onClose={closeEncryptionKeyDialog}
418419
onAccept={acceptKey}
419420
/>

yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2295,10 +2295,10 @@ __metadata:
22952295
languageName: node
22962296
linkType: hard
22972297

2298-
"@mui/core-downloads-tracker@npm:^5.11.2":
2299-
version: 5.11.2
2300-
resolution: "@mui/core-downloads-tracker@npm:5.11.2"
2301-
checksum: 1f2c45ef37b13829fa2331811548cdd3f3cb94e384513db8820533570c8ef4569e5f835f8757a48d783553f44af3f4ed2f93d402891e27718fcc58e16129a874
2298+
"@mui/core-downloads-tracker@npm:^5.11.3":
2299+
version: 5.11.3
2300+
resolution: "@mui/core-downloads-tracker@npm:5.11.3"
2301+
checksum: 0bc6ad3e2bc9170cf2fc1de749c12c1255ccf6fe17b9df047fa6a69d3a1965413a891b01dfef2939f0af7273693479b08ebd85ef3cc2e7c5e5750eced6ae15d7
23022302
languageName: node
23032303
linkType: hard
23042304

@@ -2318,13 +2318,13 @@ __metadata:
23182318
languageName: node
23192319
linkType: hard
23202320

2321-
"@mui/material@npm:^5.11.2":
2322-
version: 5.11.2
2323-
resolution: "@mui/material@npm:5.11.2"
2321+
"@mui/material@npm:^5.11.3":
2322+
version: 5.11.3
2323+
resolution: "@mui/material@npm:5.11.3"
23242324
dependencies:
23252325
"@babel/runtime": ^7.20.7
23262326
"@mui/base": 5.0.0-alpha.112
2327-
"@mui/core-downloads-tracker": ^5.11.2
2327+
"@mui/core-downloads-tracker": ^5.11.3
23282328
"@mui/system": ^5.11.2
23292329
"@mui/types": ^7.2.3
23302330
"@mui/utils": ^5.11.2
@@ -2347,7 +2347,7 @@ __metadata:
23472347
optional: true
23482348
"@types/react":
23492349
optional: true
2350-
checksum: 4f2baa4b4d8f7842b081e9e919172020f7055e33c24af36c5a458eac1a76ff3e896651fdf21daa523a68ac0bfb3670864c1b4dec9fae6d8fadf2b602f14f95ea
2350+
checksum: aa96078c51367315b9452a4a4fc7fe16aba3338bf5a8455f9c35d9f290d7d50c47e0af85124f0dbbbfd86c99b02d82039f0b923e98d93f7a04d409ba0ac41beb
23512351
languageName: node
23522352
linkType: hard
23532353

@@ -3870,7 +3870,7 @@ __metadata:
38703870
"@emotion/styled": ^11.10.5
38713871
"@fontsource/roboto": ^4.5.8
38723872
"@mui/icons-material": ^5.11.0
3873-
"@mui/material": ^5.11.2
3873+
"@mui/material": ^5.11.3
38743874
"@shopify/react-web-worker": ^5.0.6
38753875
"@tauri-apps/api": ^1.2.0
38763876
"@tauri-apps/cli": ^1.2.2

0 commit comments

Comments
 (0)