Browse Source

a bit of cleanup

pull/266/head
Hunter Thornsberry 2 years ago
parent
commit
9c6aff534a
  1. 7
      src/components/Form/FormPasswordGenerator.tsx
  2. 3
      src/components/PageComponents/Channel.tsx
  3. 29
      src/components/UI/Generator.tsx

7
src/components/Form/FormPasswordGenerator.tsx

@ -14,13 +14,6 @@ import type {
control,
field,
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) {
const [password, createPassword] = useState<string>("");
const generate = () => {
let generatedPass = "VHl1OTVpY7TAly0jGF0X2A==";
return generatedPass
}
return (
<Controller
name={field.name}

3
src/components/PageComponents/Channel.tsx

@ -81,7 +81,8 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
label: "pre-Shared Key",
description: "256, 128, or 8 bit PSKs allowed",
properties: {
// act
passwordValue: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
devicePSKBitCount: channel?.settings?.psk.length
},
},
{

29
src/components/UI/Generator.tsx

@ -50,28 +50,15 @@ export interface GeneratorProps
extends React.BaseHTMLAttributes<HTMLElement>,
VariantProps<typeof generatorVariants>
{
devicePSKBitCount?: number;
passwordValue?: string;
textValue?: string;
}
const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
({ passwordValue, textValue, className, variant, size, ...props }, ref) => {
const [pass, setPass] = useState<string>("");
const [bitCount, setBits] = useState<string>("bit256");
const generate = () => {
let generated = "thisisapass";
if (bitCount == "bit8") {
generated = btoa(cryptoRandomString({length: 1, type: 'alphanumeric'}));
}
if (bitCount == "bit128") {
generated = btoa(cryptoRandomString({length: 16, type: 'alphanumeric'}));
}
if (bitCount == "bit256") {
generated = btoa(cryptoRandomString({length: 32, type: 'alphanumeric'}));
}
return generated;
};
({ devicePSKBitCount, passwordValue, textValue, className, variant, size, ...props }, ref) => {
const [pass, setPass] = useState<string>(passwordValue ?? "");
const [bitCount, setBits] = useState<string>(devicePSKBitCount?.toString() ?? "");
return (
<>
@ -87,9 +74,9 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem key="bit256" value="bit256">256 bit</SelectItem>
<SelectItem key="bit128" value="bit128">128 bit</SelectItem>
<SelectItem key="bit8" value="bit8">8 bit</SelectItem>
<SelectItem key="bit256" value="32">256 bit</SelectItem>
<SelectItem key="bit128" value="16">128 bit</SelectItem>
<SelectItem key="bit8" value="1">8 bit</SelectItem>
</SelectContent>
</Select>
<Button
@ -98,7 +85,7 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
ref={ref}
{...props}
onClick={() => {
setPass(generate());
setPass(btoa(cryptoRandomString({length: Number.parseInt(bitCount), type: 'alphanumeric'})));
}}
>
{textValue}

Loading…
Cancel
Save