Skip to content

Commit

Permalink
a bit of cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Hunter275 committed Jul 28, 2024
1 parent 38b7e60 commit 9c6aff5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 29 deletions.
7 changes: 0 additions & 7 deletions src/components/Form/FormPasswordGenerator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion src/components/PageComponents/Channel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
},
{
Expand Down
29 changes: 8 additions & 21 deletions src/components/UI/Generator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit 9c6aff5

Please sign in to comment.