From e00bdfaa750287760b0749516ddfb996e79b10a4 Mon Sep 17 00:00:00 2001 From: David Tayar <38883783+XDavidT@users.noreply.github.com> Date: Sun, 8 Jun 2025 10:46:29 +0300 Subject: [PATCH] Adding bcrypt support --- package-lock.json | 15 +++ package.json | 2 + src/pages/tools/string/bcrypt/Component.tsx | 118 ++++++++++++++++++++ src/pages/tools/string/bcrypt/meta.tsx | 21 ++++ src/pages/tools/string/index.ts | 4 +- 5 files changed, 159 insertions(+), 1 deletion(-) create mode 100644 src/pages/tools/string/bcrypt/Component.tsx create mode 100644 src/pages/tools/string/bcrypt/meta.tsx diff --git a/package-lock.json b/package-lock.json index e501cc8..c56d42a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index ed7ebcf..e709af9 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/pages/tools/string/bcrypt/Component.tsx b/src/pages/tools/string/bcrypt/Component.tsx new file mode 100644 index 0000000..4da3927 --- /dev/null +++ b/src/pages/tools/string/bcrypt/Component.tsx @@ -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 = ({ 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 ( + + }> + 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. + + + + + + + + Input Text + + setInput(e.target.value)} + placeholder="Enter text to hash" + variant="outlined" + /> + + + + + Salt Rounds: {saltRounds} + + setSaltRounds(value as number)} + min={4} + max={12} + step={1} + marks + valueLabelDisplay="auto" + /> + + + + + {error && ( + + {error} + + )} + + {hash && ( + + + Generated Hash + + + + + + + )} + + + + + ); +}; + +export default Component; diff --git a/src/pages/tools/string/bcrypt/meta.tsx b/src/pages/tools/string/bcrypt/meta.tsx new file mode 100644 index 0000000..45239cb --- /dev/null +++ b/src/pages/tools/string/bcrypt/meta.tsx @@ -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 +}); diff --git a/src/pages/tools/string/index.ts b/src/pages/tools/string/index.ts index e7cecd4..5c22662 100644 --- a/src/pages/tools/string/index.ts +++ b/src/pages/tools/string/index.ts @@ -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 ];