Connect UserGenPage to API. Base 32 string seems to pass quality checks, shorter do not.

This commit is contained in:
Reckless_Satoshi
2022-01-02 10:27:40 -08:00
parent fb9fb88ab7
commit f4644836d3
2 changed files with 22 additions and 3 deletions

View File

@ -117,7 +117,7 @@ class UserGenerator(APIView):
# Deny user gen if entropy below 128 bits or 0.7 shannon heterogeneity # Deny user gen if entropy below 128 bits or 0.7 shannon heterogeneity
if bits_entropy < 128 or shannon_entropy < 0.7: if bits_entropy < 128 or shannon_entropy < 0.7:
context['Bad Request'] = 'The token does not have enough entropy' context['bad_request'] = 'The token does not have enough entropy'
return Response(context, status=status.HTTP_400_BAD_REQUEST) return Response(context, status=status.HTTP_400_BAD_REQUEST)
# Hashes the token, only 1 iteration. Maybe more is better. # Hashes the token, only 1 iteration. Maybe more is better.

View File

@ -4,10 +4,11 @@ export default class UserGenPage extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { this.state = {
token: this.genBase62Token(30), token: this.genBase62Token(32),
}; };
this.token = this.genBase62Token(30); this.getGeneratedUser();
} }
// sort of cryptographically strong function to generate Base62 token client-side // sort of cryptographically strong function to generate Base62 token client-side
genBase62Token(length) genBase62Token(length)
{ {
@ -19,11 +20,29 @@ export default class UserGenPage extends Component {
.substring(0, length); .substring(0, length);
} }
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,
});
});
}
render() { render() {
return ( return (
<div> <div>
<p>This is the landing and user generator page</p> <p>This is the landing and user generator page</p>
<p>Have a token of appreciation {this.state.token}</p> <p>Have a token of appreciation {this.state.token}</p>
<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>
</div> </div>
); );
} }