a bit of cleanup
This commit is contained in:
@@ -14,13 +14,6 @@ import type {
|
|||||||
control,
|
control,
|
||||||
field,
|
field,
|
||||||
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) {
|
}: GenericFormElementProps<T, PasswordGeneratorProps<T>>) {
|
||||||
const [password, createPassword] = useState<string>("");
|
|
||||||
|
|
||||||
const generate = () => {
|
|
||||||
let generatedPass = "VHl1OTVpY7TAly0jGF0X2A==";
|
|
||||||
return generatedPass
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Controller
|
<Controller
|
||||||
name={field.name}
|
name={field.name}
|
||||||
|
|||||||
@@ -81,7 +81,8 @@ export const Channel = ({ channel }: SettingsPanelProps): JSX.Element => {
|
|||||||
label: "pre-Shared Key",
|
label: "pre-Shared Key",
|
||||||
description: "256, 128, or 8 bit PSKs allowed",
|
description: "256, 128, or 8 bit PSKs allowed",
|
||||||
properties: {
|
properties: {
|
||||||
// act
|
passwordValue: fromByteArray(channel?.settings?.psk ?? new Uint8Array(0)),
|
||||||
|
devicePSKBitCount: channel?.settings?.psk.length
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -50,28 +50,15 @@ export interface GeneratorProps
|
|||||||
extends React.BaseHTMLAttributes<HTMLElement>,
|
extends React.BaseHTMLAttributes<HTMLElement>,
|
||||||
VariantProps<typeof generatorVariants>
|
VariantProps<typeof generatorVariants>
|
||||||
{
|
{
|
||||||
|
devicePSKBitCount?: number;
|
||||||
passwordValue?: string;
|
passwordValue?: string;
|
||||||
textValue?: string;
|
textValue?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
|
const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
|
||||||
({ passwordValue, textValue, className, variant, size, ...props }, ref) => {
|
({ devicePSKBitCount, passwordValue, textValue, className, variant, size, ...props }, ref) => {
|
||||||
const [pass, setPass] = useState<string>("");
|
const [pass, setPass] = useState<string>(passwordValue ?? "");
|
||||||
const [bitCount, setBits] = useState<string>("bit256");
|
const [bitCount, setBits] = useState<string>(devicePSKBitCount?.toString() ?? "");
|
||||||
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -87,9 +74,9 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
|
|||||||
<SelectValue />
|
<SelectValue />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
<SelectContent>
|
<SelectContent>
|
||||||
<SelectItem key="bit256" value="bit256">256 bit</SelectItem>
|
<SelectItem key="bit256" value="32">256 bit</SelectItem>
|
||||||
<SelectItem key="bit128" value="bit128">128 bit</SelectItem>
|
<SelectItem key="bit128" value="16">128 bit</SelectItem>
|
||||||
<SelectItem key="bit8" value="bit8">8 bit</SelectItem>
|
<SelectItem key="bit8" value="1">8 bit</SelectItem>
|
||||||
</SelectContent>
|
</SelectContent>
|
||||||
</Select>
|
</Select>
|
||||||
<Button
|
<Button
|
||||||
@@ -98,7 +85,7 @@ const Generator = React.forwardRef<HTMLButtonElement, GeneratorProps>(
|
|||||||
ref={ref}
|
ref={ref}
|
||||||
{...props}
|
{...props}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setPass(generate());
|
setPass(btoa(cryptoRandomString({length: Number.parseInt(bitCount), type: 'alphanumeric'})));
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{textValue}
|
{textValue}
|
||||||
|
|||||||
Reference in New Issue
Block a user