mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-11-14 03:48:34 +05:30
Adding bcrypt support
This commit is contained in:
parent
d25f7ca557
commit
e00bdfaa75
5 changed files with 159 additions and 1 deletions
15
package-lock.json
generated
15
package-lock.json
generated
|
|
@ -23,6 +23,7 @@
|
|||
"@types/lodash": "^4.17.5",
|
||||
"@types/morsee": "^1.0.2",
|
||||
"@types/omggif": "^1.0.5",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"browser-image-compression": "^2.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"color": "^4.2.3",
|
||||
|
|
@ -59,6 +60,7 @@
|
|||
"@iconify/react": "^5.2.0",
|
||||
"@testing-library/jest-dom": "^6.4.5",
|
||||
"@testing-library/react": "^14.3.1",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/color": "^3.0.6",
|
||||
"@types/color-rgba": "^2.1.2",
|
||||
"@types/node": "^20.12.12",
|
||||
|
|
@ -3267,6 +3269,13 @@
|
|||
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@types/bcryptjs": {
|
||||
"version": "2.4.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/bcryptjs/-/bcryptjs-2.4.6.tgz",
|
||||
"integrity": "sha512-9xlo6R2qDs5uixm0bcIqCeMCE6HiQsIyel9KQySStiyqNl2tnj2mP3DX1Nf56MD6KMenNNlBBsy3LJ7gUEQPXQ==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/@types/color": {
|
||||
"version": "3.0.6",
|
||||
"resolved": "https://registry.npmjs.org/@types/color/-/color-3.0.6.tgz",
|
||||
|
|
@ -4232,6 +4241,12 @@
|
|||
}
|
||||
]
|
||||
},
|
||||
"node_modules/bcryptjs": {
|
||||
"version": "2.4.3",
|
||||
"resolved": "https://registry.npmjs.org/bcryptjs/-/bcryptjs-2.4.3.tgz",
|
||||
"integrity": "sha512-V/Hy/X9Vt7f3BbPJEi8BdVFMByHi+jNXrYkW3huaybV/kQ0KJg0Y6PkEMbn+zeT+i+SiKZ/HMqJGIIt4LZDqNQ==",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/binary-extensions": {
|
||||
"version": "2.3.0",
|
||||
"resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.3.0.tgz",
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
"@types/lodash": "^4.17.5",
|
||||
"@types/morsee": "^1.0.2",
|
||||
"@types/omggif": "^1.0.5",
|
||||
"bcryptjs": "^2.4.3",
|
||||
"browser-image-compression": "^2.0.2",
|
||||
"buffer": "^6.0.3",
|
||||
"color": "^4.2.3",
|
||||
|
|
@ -76,6 +77,7 @@
|
|||
"@iconify/react": "^5.2.0",
|
||||
"@testing-library/jest-dom": "^6.4.5",
|
||||
"@testing-library/react": "^14.3.1",
|
||||
"@types/bcryptjs": "^2.4.6",
|
||||
"@types/color": "^3.0.6",
|
||||
"@types/color-rgba": "^2.1.2",
|
||||
"@types/node": "^20.12.12",
|
||||
|
|
|
|||
118
src/pages/tools/string/bcrypt/Component.tsx
Normal file
118
src/pages/tools/string/bcrypt/Component.tsx
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
import React, { useState } from 'react';
|
||||
import {
|
||||
Box,
|
||||
Card,
|
||||
CardContent,
|
||||
TextField,
|
||||
Typography,
|
||||
Slider,
|
||||
Button,
|
||||
Alert
|
||||
} from '@mui/material';
|
||||
import { ToolComponentProps } from '../../../../tools/defineTool';
|
||||
import InfoIcon from '@mui/icons-material/Info';
|
||||
|
||||
const Component: React.FC<ToolComponentProps> = ({ title }) => {
|
||||
const [input, setInput] = useState('');
|
||||
const [hash, setHash] = useState('');
|
||||
const [saltRounds, setSaltRounds] = useState(10);
|
||||
const [error, setError] = useState('');
|
||||
|
||||
const generateHash = async () => {
|
||||
try {
|
||||
setError('');
|
||||
const bcrypt = await import('bcryptjs');
|
||||
const hashedPassword = await bcrypt.hash(input, saltRounds);
|
||||
setHash(hashedPassword);
|
||||
} catch (err) {
|
||||
setError('Failed to generate hash. Please try again.');
|
||||
console.error('Hash generation error:', err);
|
||||
}
|
||||
};
|
||||
|
||||
const copyToClipboard = () => {
|
||||
navigator.clipboard.writeText(hash);
|
||||
};
|
||||
|
||||
return (
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||
<Alert severity="info" icon={<InfoIcon />}>
|
||||
BCrypt is a password hashing function designed to be computationally
|
||||
expensive, making it resistant to brute-force attacks. Higher salt
|
||||
rounds increase security but also increase computation time.
|
||||
</Alert>
|
||||
|
||||
<Card>
|
||||
<CardContent>
|
||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||
<Box>
|
||||
<Typography variant="subtitle1" gutterBottom>
|
||||
Input Text
|
||||
</Typography>
|
||||
<TextField
|
||||
fullWidth
|
||||
value={input}
|
||||
onChange={(e) => setInput(e.target.value)}
|
||||
placeholder="Enter text to hash"
|
||||
variant="outlined"
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Box>
|
||||
<Typography variant="subtitle1" gutterBottom>
|
||||
Salt Rounds: {saltRounds}
|
||||
</Typography>
|
||||
<Slider
|
||||
value={saltRounds}
|
||||
onChange={(_, value) => setSaltRounds(value as number)}
|
||||
min={4}
|
||||
max={12}
|
||||
step={1}
|
||||
marks
|
||||
valueLabelDisplay="auto"
|
||||
/>
|
||||
</Box>
|
||||
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={generateHash}
|
||||
disabled={!input}
|
||||
fullWidth
|
||||
>
|
||||
Generate Hash
|
||||
</Button>
|
||||
|
||||
{error && (
|
||||
<Typography color="error" variant="body2">
|
||||
{error}
|
||||
</Typography>
|
||||
)}
|
||||
|
||||
{hash && (
|
||||
<Box>
|
||||
<Typography variant="subtitle1" gutterBottom>
|
||||
Generated Hash
|
||||
</Typography>
|
||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||
<TextField
|
||||
fullWidth
|
||||
value={hash}
|
||||
InputProps={{
|
||||
readOnly: true
|
||||
}}
|
||||
variant="outlined"
|
||||
/>
|
||||
<Button variant="outlined" onClick={copyToClipboard}>
|
||||
Copy
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
)}
|
||||
</Box>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
||||
export default Component;
|
||||
21
src/pages/tools/string/bcrypt/meta.tsx
Normal file
21
src/pages/tools/string/bcrypt/meta.tsx
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
import { defineTool } from '../../../../tools/defineTool';
|
||||
import { lazy } from 'react';
|
||||
|
||||
const Component = lazy(() => import('./Component'));
|
||||
|
||||
export const tool = defineTool('string', {
|
||||
path: 'bcrypt',
|
||||
name: 'BCrypt Hash',
|
||||
description: 'Generate BCrypt hashes from text with customizable salt rounds',
|
||||
shortDescription: 'Generate secure BCrypt hashes',
|
||||
keywords: [
|
||||
'bcrypt',
|
||||
'hash',
|
||||
'password',
|
||||
'security',
|
||||
'encryption',
|
||||
'cryptography'
|
||||
],
|
||||
icon: 'mdi:lock',
|
||||
component: Component
|
||||
});
|
||||
|
|
@ -16,6 +16,7 @@ import { tool as stringRepeat } from './repeat/meta';
|
|||
import { tool as stringTruncate } from './truncate/meta';
|
||||
import { tool as stringBase64 } from './base64/meta';
|
||||
import { tool as stringStatistic } from './statistic/meta';
|
||||
import { tool as stringBcrypt } from './bcrypt/meta';
|
||||
|
||||
export const stringTools = [
|
||||
stringSplit,
|
||||
|
|
@ -35,5 +36,6 @@ export const stringTools = [
|
|||
stringRotate,
|
||||
stringRot13,
|
||||
stringBase64,
|
||||
stringStatistic
|
||||
stringStatistic,
|
||||
stringBcrypt
|
||||
];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue