mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-13 02:46:28 +00:00
Connect UserGenPage to API. Base 32 string seems to pass quality checks, shorter do not.
This commit is contained in:
parent
fb9fb88ab7
commit
f4644836d3
@ -117,7 +117,7 @@ class UserGenerator(APIView):
|
||||
|
||||
# Deny user gen if entropy below 128 bits or 0.7 shannon heterogeneity
|
||||
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)
|
||||
|
||||
# Hashes the token, only 1 iteration. Maybe more is better.
|
||||
|
@ -4,10 +4,11 @@ export default class UserGenPage extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
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
|
||||
genBase62Token(length)
|
||||
{
|
||||
@ -19,11 +20,29 @@ export default class UserGenPage extends Component {
|
||||
.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() {
|
||||
return (
|
||||
<div>
|
||||
<p>This is the landing and user generator page</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>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user