2022-01-02 00:19:18 +00:00
|
|
|
import React, { Component } from "react";
|
|
|
|
|
2022-01-02 15:19:49 +00:00
|
|
|
export default class UserGenPage extends Component {
|
2022-01-02 17:42:33 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2022-01-02 18:27:40 +00:00
|
|
|
token: this.genBase62Token(32),
|
2022-01-02 17:42:33 +00:00
|
|
|
};
|
2022-01-02 18:27:40 +00:00
|
|
|
this.getGeneratedUser();
|
2022-01-02 17:42:33 +00:00
|
|
|
}
|
2022-01-02 18:27:40 +00:00
|
|
|
|
2022-01-02 17:42:33 +00:00
|
|
|
// sort of cryptographically strong function to generate Base62 token client-side
|
|
|
|
genBase62Token(length)
|
|
|
|
{
|
|
|
|
return window.btoa(Array.from(
|
|
|
|
window.crypto.getRandomValues(
|
|
|
|
new Uint8Array(length * 2)))
|
|
|
|
.map((b) => String.fromCharCode(b))
|
|
|
|
.join("")).replace(/[+/]/g, "")
|
|
|
|
.substring(0, length);
|
|
|
|
}
|
|
|
|
|
2022-01-02 18:27:40 +00:00
|
|
|
getGeneratedUser() {
|
|
|
|
fetch('/api/usergen' + '?token=' + this.state.token)
|
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
this.setState({
|
|
|
|
nickname: data.nickname,
|
|
|
|
bit_entropy: data.token_bits_entropy,
|
|
|
|
shannon_entropy: data.token_shannon_entropy,
|
|
|
|
bad_request: data.bad_request,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-01-02 17:42:33 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<p>This is the landing and user generator page</p>
|
|
|
|
<p>Have a token of appreciation {this.state.token}</p>
|
2022-01-02 18:27:40 +00:00
|
|
|
<p>Username is {this.state.nickname}</p>
|
|
|
|
<p>Shannon entropy is {this.state.shannon_entropy}</p>
|
|
|
|
<p>Entropy depth is {this.state.bit_entropy} bits</p>
|
|
|
|
<p>Bad request: {this.state.bad_request}</p>
|
2022-01-02 17:42:33 +00:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
2022-01-02 00:19:18 +00:00
|
|
|
|
|
|
|
}
|