Skip to content

Commit 3a0b612

Browse files
committed
feat(new tool): htpasswd generator
Fix CorentinTh#430 and CorentinTh#807
1 parent e073b2b commit 3a0b612

File tree

5 files changed

+84
-6
lines changed

5 files changed

+84
-6
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"@vueuse/core": "^10.3.0",
4747
"@vueuse/head": "^1.0.0",
4848
"@vueuse/router": "^10.0.0",
49+
"apache-md5": "^1.1.8",
4950
"bcryptjs": "^2.4.3",
5051
"change-case": "^4.1.2",
5152
"colord": "^2.9.3",

pnpm-lock.yaml

Lines changed: 14 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<script setup lang="ts">
2+
import { hashSync } from 'bcryptjs';
3+
import md5 from 'apache-md5';
4+
import TextareaCopyable from '@/components/TextareaCopyable.vue';
5+
6+
const username = ref('');
7+
const password = ref('');
8+
const hashMethod = ref('bcrypt');
9+
10+
const htpasswd = computed(() => {
11+
if (username.value === '' || password.value === '') {
12+
return '# username and password must not be empty';
13+
}
14+
let hash;
15+
if (hashMethod.value === 'md5') {
16+
hash = md5(password.value);
17+
}
18+
else {
19+
hash = hashSync(password.value, 10);
20+
}
21+
return `${username.value}:${hash}`;
22+
});
23+
</script>
24+
25+
<template>
26+
<div>
27+
<c-input-text
28+
v-model:value="username"
29+
label="Username"
30+
placeholder="Your username..."
31+
clearable raw-text mb-5
32+
/>
33+
<c-input-text
34+
v-model:value="password"
35+
label="Password"
36+
placeholder="Your password..."
37+
clearable
38+
raw-text
39+
mb-2
40+
type="password"
41+
/>
42+
43+
<c-select
44+
v-model:value="hashMethod"
45+
label="Hash method:"
46+
:options="['bcrypt', 'md5']"
47+
/>
48+
49+
<n-divider />
50+
51+
<n-form-item label="htpasswd content:">
52+
<TextareaCopyable :value="htpasswd" />
53+
</n-form-item>
54+
</div>
55+
</template>

src/tools/htpasswd-generator/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { PasswordRound } from '@vicons/material';
2+
import { defineTool } from '../tool';
3+
4+
export const tool = defineTool({
5+
name: 'Htpasswd/htaccess generator',
6+
path: '/htpasswd-generator',
7+
description: 'htpassword/htaccess user/password generator',
8+
keywords: ['htpasswd', 'htaccess', 'bcrypt', 'password'],
9+
component: () => import('./htpasswd-generator.vue'),
10+
icon: PasswordRound,
11+
createdAt: new Date('2024-02-20'),
12+
});

src/tools/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { tool as base64FileConverter } from './base64-file-converter';
22
import { tool as base64StringConverter } from './base64-string-converter';
33
import { tool as basicAuthGenerator } from './basic-auth-generator';
44
import { tool as textToUnicode } from './text-to-unicode';
5+
import { tool as htpasswdGenerator } from './htpasswd-generator';
56
import { tool as pdfSignatureChecker } from './pdf-signature-checker';
67
import { tool as numeronymGenerator } from './numeronym-generator';
78
import { tool as macAddressGenerator } from './mac-address-generator';
@@ -113,6 +114,7 @@ export const toolsByCategory: ToolCategory[] = [
113114
urlParser,
114115
deviceInformation,
115116
basicAuthGenerator,
117+
htpasswdGenerator,
116118
metaTagGenerator,
117119
otpCodeGeneratorAndValidator,
118120
mimeTypes,

0 commit comments

Comments
 (0)