Skip to content

Commit

Permalink
bcrypt password in frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieuancelin committed Dec 16, 2024
1 parent ba98525 commit 16c54e3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
5 changes: 4 additions & 1 deletion otoroshi/app/next/plugins/auth.scala
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,10 @@ object SimpleBasicAuthConfig {
),
"users" -> Json.obj(
"type" -> "object",
"label" -> "Users"
"label" -> "Users",
"props" -> Json.obj(
"bcryptable" -> true
)
)
))
}
Expand Down
28 changes: 19 additions & 9 deletions otoroshi/javascript/src/components/inputs/ObjectInput.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import { Help } from './Help';
import bcrypt from 'bcryptjs';

export class ObjectInput extends React.Component {
state = {
Expand Down Expand Up @@ -103,6 +104,10 @@ export class ObjectInput extends React.Component {
}
};

disableBcrypt = (value) => {
return value.startsWith("$2a$") || value.startsWith("$2$") || value.startsWith("$2b$") || value.startsWith("$2x$") || value.startsWith("$2y$")
}

render() {
const { data } = this.state;
const props = this.props;
Expand Down Expand Up @@ -160,15 +165,20 @@ export class ObjectInput extends React.Component {
{props.valueRenderer &&
props.valueRenderer(key, value, idx, (e) => this.changeValue(idx, key, e))}
{!props.valueRenderer && (
<input
disabled={props.disabled}
type="text"
className="form-control"
placeholder={props.placeholderValue}
value={value}
onChange={(e) => this.changeValue(idx, key, e)}
/>
)}
<>
<input
disabled={props.disabled}
type="text"
className="form-control"
placeholder={props.placeholderValue}
value={value}
onChange={(e) => this.changeValue(idx, key, e)}
/>
{props.bcryptable ? <button className="btn btn-outline-secondary" type="button" disabled={this.disableBcrypt} onClick={e => {
this.changeValue(idx, key, { target: { value: bcrypt.hashSync(value, 10) }})
}}>bcrypt</button> : null}
</>
)}
</>
)}
<span className="input-group-btn">
Expand Down
6 changes: 3 additions & 3 deletions otoroshi/javascript/src/components/inputs/TextInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,15 @@ export class VerticalTextInput extends Component {
onDrop={this.props.onDrop || this.onDrop}
onDragOver={(e) => e.preventDefault()}
/>
{this.props.prefix && (
{this.props.suffix && (
<span
className="input-group-text"
onClick={
this.props.suffixCb ? () => this.props.suffixCb(this.props.value) : undefined
}
style={this.props.prefixStyle || {}}
style={this.props.suffixStyle || {}}
>
{this.props.prefix}
{this.props.suffix}
</span>
)}
</div>
Expand Down
1 change: 1 addition & 0 deletions otoroshi/javascript/src/components/nginputs/inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,7 @@ export class NgObjectRenderer extends Component {
ngOptions={{
spread: true,
}}
bcryptable={props.bcryptable}
label={null}
placeholderKey={props.placeholderKey}
placeholderValue={props.placeholderValue}
Expand Down

0 comments on commit 16c54e3

Please sign in to comment.