Random Stream Key Generator (#2690)
* add a new random stream key generator * fix a typo
This commit is contained in:
committed by
GitHub
parent
be1ce74a5d
commit
b75c6a886a
@@ -35,6 +35,24 @@ const saveKeys = async (keys, setError) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const generateRndKey = () => {
|
||||||
|
let defaultKey = '';
|
||||||
|
let isValidStreamKey = false;
|
||||||
|
const streamKeyRegex = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[!@#$%^&*]).{8,192}$/;
|
||||||
|
const s = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*';
|
||||||
|
|
||||||
|
while (!isValidStreamKey) {
|
||||||
|
const temp = Array.apply(20, Array(30))
|
||||||
|
.map(() => s.charAt(Math.floor(Math.random() * s.length)))
|
||||||
|
.join('');
|
||||||
|
if (streamKeyRegex.test(temp)) {
|
||||||
|
isValidStreamKey = true;
|
||||||
|
defaultKey = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return defaultKey;
|
||||||
|
};
|
||||||
|
|
||||||
const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setError }) => {
|
const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setError }) => {
|
||||||
const handleAddKey = (newkey: any) => {
|
const handleAddKey = (newkey: any) => {
|
||||||
const updatedKeys = [...streamKeys, newkey];
|
const updatedKeys = [...streamKeys, newkey];
|
||||||
@@ -50,10 +68,7 @@ const AddKeyForm = ({ setShowAddKeyForm, setFieldInConfigState, streamKeys, setE
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Default auto-generated key
|
// Default auto-generated key
|
||||||
let defaultKey = '';
|
const defaultKey = generateRndKey();
|
||||||
for (let i = 0; i < 3; i += 1) {
|
|
||||||
defaultKey += Math.random().toString(36).substring(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form layout="inline" autoComplete="off" onFinish={handleAddKey}>
|
<Form layout="inline" autoComplete="off" onFinish={handleAddKey}>
|
||||||
|
|||||||
Reference in New Issue
Block a user