mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-16 14:08:12 +00:00
fix: password random (#7615)
* fix: password random * fix: code --------- Co-authored-by: 杨国璇 <ygx@Hello-word.local>
This commit is contained in:
parent
de14104af6
commit
a53d4978d1
@ -16,8 +16,7 @@ class ButtonQR extends React.Component {
|
|||||||
this.state = {
|
this.state = {
|
||||||
isPopoverOpen: false
|
isPopoverOpen: false
|
||||||
};
|
};
|
||||||
|
this.btn = null;
|
||||||
this.btnID = 'btn-' + Math.random().toString().substr(2, 5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
togglePopover = () => {
|
togglePopover = () => {
|
||||||
@ -30,14 +29,16 @@ class ButtonQR extends React.Component {
|
|||||||
const { link } = this.props;
|
const { link } = this.props;
|
||||||
const { isPopoverOpen } = this.state;
|
const { isPopoverOpen } = this.state;
|
||||||
return (
|
return (
|
||||||
<div className="ml-2">
|
<div className="ml-2" ref={ref => this.btn = ref}>
|
||||||
<Button outline color="primary" className="btn-icon btn-qr-code-icon sf3-font sf3-font-qr-code" id={this.btnID} onClick={this.togglePopover} type="button"></Button>
|
<Button outline color="primary" className="btn-icon btn-qr-code-icon sf3-font sf3-font-qr-code" onClick={this.togglePopover} type="button"></Button>
|
||||||
<Popover placement="bottom" isOpen={isPopoverOpen} target={this.btnID} toggle={this.togglePopover}>
|
{this.btn && (
|
||||||
<PopoverBody>
|
<Popover placement="bottom" isOpen={isPopoverOpen} target={this.btn} toggle={this.togglePopover}>
|
||||||
<QRCodeSVG value={link} size={128} />
|
<PopoverBody>
|
||||||
<p className="m-0 mt-1 text-center" style={{ 'maxWidth': '128px' }}>{gettext('Scan the QR code to view the shared content directly')}</p>
|
<QRCodeSVG value={link} size={128} />
|
||||||
</PopoverBody>
|
<p className="m-0 mt-1 text-center" style={{ 'maxWidth': '128px' }}>{gettext('Scan the QR code to view the shared content directly')}</p>
|
||||||
</Popover>
|
</PopoverBody>
|
||||||
|
</Popover>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
|
|||||||
import { Button, Modal, Input, ModalBody, ModalFooter, Label, Form, InputGroup, FormGroup } from 'reactstrap';
|
import { Button, Modal, Input, ModalBody, ModalFooter, Label, Form, InputGroup, FormGroup } from 'reactstrap';
|
||||||
import { gettext } from '../../utils/constants';
|
import { gettext } from '../../utils/constants';
|
||||||
import SeahubModalHeader from '@/components/common/seahub-modal-header';
|
import SeahubModalHeader from '@/components/common/seahub-modal-header';
|
||||||
|
import { Utils } from '../../utils/utils';
|
||||||
|
|
||||||
const propTypes = {
|
const propTypes = {
|
||||||
toggle: PropTypes.func.isRequired,
|
toggle: PropTypes.func.isRequired,
|
||||||
@ -48,7 +49,7 @@ class AddOrgUserDialog extends React.Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
generatePassword = () => {
|
generatePassword = () => {
|
||||||
let val = Math.random().toString(36).substr(5);
|
let val = Utils.generatePassword(8);
|
||||||
this.setState({
|
this.setState({
|
||||||
password: val,
|
password: val,
|
||||||
newPassword: val,
|
newPassword: val,
|
||||||
|
@ -1578,21 +1578,34 @@ export const Utils = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
generatePassword: function (length, hasNum = 1, hasChar = 1, hasSymbol = 1) {
|
generateSecureRandomInRange: function (min, max) {
|
||||||
|
const start = Math.min(min, max);
|
||||||
|
const end = Math.max(min, max);
|
||||||
|
const range = end - start + 1;
|
||||||
|
const byteSize = Math.ceil(Math.log2(range) / 8);
|
||||||
|
|
||||||
|
const randomBytes = new Uint8Array(byteSize);
|
||||||
|
window.crypto.getRandomValues(randomBytes);
|
||||||
|
|
||||||
|
const randomValue = Array.from(randomBytes).reduce((pre, byte) => (pre << 8) | byte, 0);
|
||||||
|
return start + (randomValue % range);
|
||||||
|
},
|
||||||
|
|
||||||
|
generatePassword: function (length) {
|
||||||
|
|
||||||
var password = '';
|
var password = '';
|
||||||
|
|
||||||
// 65~90:A~Z
|
// 65~90:A~Z
|
||||||
password += String.fromCharCode(Math.floor((Math.random() * (90 - 65)) + 65));
|
password += String.fromCharCode(this.generateSecureRandomInRange(65, 90));
|
||||||
|
|
||||||
// 97~122:a~z
|
// 97~122:a~z
|
||||||
password += String.fromCharCode(Math.floor((Math.random() * (122 - 97)) + 97));
|
password += String.fromCharCode(this.generateSecureRandomInRange(97, 122));
|
||||||
|
|
||||||
// 48~57:0~9
|
// 48~57:0~9
|
||||||
password += String.fromCharCode(Math.floor((Math.random() * (57 - 48)) + 48));
|
password += String.fromCharCode(this.generateSecureRandomInRange(48, 57));
|
||||||
|
|
||||||
// 33~47:!~/
|
// 33~47:!~/
|
||||||
password += String.fromCharCode(Math.floor((Math.random() * (47 - 33)) + 33));
|
password += String.fromCharCode(this.generateSecureRandomInRange(33, 47));
|
||||||
|
|
||||||
// 33~47:!~/
|
// 33~47:!~/
|
||||||
// 48~57:0~9
|
// 48~57:0~9
|
||||||
@ -1602,8 +1615,7 @@ export const Utils = {
|
|||||||
// 97~122:a~z
|
// 97~122:a~z
|
||||||
// 123~127:{~
|
// 123~127:{~
|
||||||
for (var i = 0; i < length - 4; i++) {
|
for (var i = 0; i < length - 4; i++) {
|
||||||
var num = Math.floor((Math.random() * (127 - 33)) + 33);
|
password += String.fromCharCode(this.generateSecureRandomInRange(33, 127));
|
||||||
password += String.fromCharCode(num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return password;
|
return password;
|
||||||
|
Loading…
Reference in New Issue
Block a user