aboutsummaryrefslogtreecommitdiff
path: root/src/tools/basic-auth-generator/basic-auth-generator.vue
blob: 975071c37b51c300db55ffea8dba8eed12f51ac4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<template>
  <div>
    <n-form-item label="Username">
      <n-input v-model:value="username" placeholder="Your username..." clearable />
    </n-form-item>
    <n-form-item label="Password">
      <n-input
        v-model:value="password"
        placeholder="Your password..."
        type="password"
        show-password-on="click"
        clearable
      />
    </n-form-item>

    <br />
    <n-card>
      <n-statistic label="Authorization header:" class="header">
        <n-scrollbar x-scrollable style="max-width: 550px; margin-bottom: -10px; padding-bottom: 10px" trigger="none">
          {{ header }}
        </n-scrollbar>
      </n-statistic>
    </n-card>
    <br />
    <n-space justify="center">
      <n-button secondary @click="copy">Copy header</n-button>
    </n-space>
  </div>
</template>

<script setup lang="ts">
import { useCopy } from '@/composable/copy';
import { textToBase64 } from '@/utils/base64';
import { computed, ref } from 'vue';

const username = ref('');
const password = ref('');
const header = computed(() => `Authorization: Basic ${textToBase64(`${username.value}:${password.value}`)}`);

const { copy } = useCopy({ source: header, text: 'Header copied to the clipboard' });
</script>

<style lang="less" scoped>
::v-deep(.n-statistic-value__content) {
  font-family: monospace;
  font-size: 17px !important;
  white-space: nowrap;
}
</style>