a bit of cleanup

This commit is contained in:
Hunter Thornsberry
2024-07-28 16:43:41 -04:00
parent 38b7e600b1
commit 9c6aff534a
3 changed files with 10 additions and 29 deletions
@@ -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}
+2 -1
View File
@@ -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
},
},
{
+8 -21
View File
@@ -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}