From 16c54e312c69ae7d067c88a46dc0c569073e7096 Mon Sep 17 00:00:00 2001 From: Mathieu Ancelin Date: Mon, 16 Dec 2024 11:42:47 +0100 Subject: [PATCH] bcrypt password in frontend --- otoroshi/app/next/plugins/auth.scala | 5 +++- .../src/components/inputs/ObjectInput.js | 28 +++++++++++++------ .../src/components/inputs/TextInput.js | 6 ++-- .../src/components/nginputs/inputs.js | 1 + 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/otoroshi/app/next/plugins/auth.scala b/otoroshi/app/next/plugins/auth.scala index 4c84809ec..d42e76161 100644 --- a/otoroshi/app/next/plugins/auth.scala +++ b/otoroshi/app/next/plugins/auth.scala @@ -675,7 +675,10 @@ object SimpleBasicAuthConfig { ), "users" -> Json.obj( "type" -> "object", - "label" -> "Users" + "label" -> "Users", + "props" -> Json.obj( + "bcryptable" -> true + ) ) )) } diff --git a/otoroshi/javascript/src/components/inputs/ObjectInput.js b/otoroshi/javascript/src/components/inputs/ObjectInput.js index 9064a4b3d..87b5a45af 100644 --- a/otoroshi/javascript/src/components/inputs/ObjectInput.js +++ b/otoroshi/javascript/src/components/inputs/ObjectInput.js @@ -1,5 +1,6 @@ import React from 'react'; import { Help } from './Help'; +import bcrypt from 'bcryptjs'; export class ObjectInput extends React.Component { state = { @@ -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; @@ -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 && ( - this.changeValue(idx, key, e)} - /> - )} + <> + this.changeValue(idx, key, e)} + /> + {props.bcryptable ? : null} + + )} )} diff --git a/otoroshi/javascript/src/components/inputs/TextInput.js b/otoroshi/javascript/src/components/inputs/TextInput.js index 6b046d7b6..3dd4335cc 100644 --- a/otoroshi/javascript/src/components/inputs/TextInput.js +++ b/otoroshi/javascript/src/components/inputs/TextInput.js @@ -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 && ( this.props.suffixCb(this.props.value) : undefined } - style={this.props.prefixStyle || {}} + style={this.props.suffixStyle || {}} > - {this.props.prefix} + {this.props.suffix} )} diff --git a/otoroshi/javascript/src/components/nginputs/inputs.js b/otoroshi/javascript/src/components/nginputs/inputs.js index 1f50ff958..9cffd65f9 100644 --- a/otoroshi/javascript/src/components/nginputs/inputs.js +++ b/otoroshi/javascript/src/components/nginputs/inputs.js @@ -868,6 +868,7 @@ export class NgObjectRenderer extends Component { ngOptions={{ spread: true, }} + bcryptable={props.bcryptable} label={null} placeholderKey={props.placeholderKey} placeholderValue={props.placeholderValue}