Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RED-302: Set Password Command Fails to Change Password Despite Valid Input #27

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,25 @@ npm run compile
```

3. Set GUI password:

Interactive mode (recommended for direct use):
```bash
operator-cli gui set password <your-password>
operator-cli gui set password
```
You will be prompted to enter the password securely.

Non-interactive mode (for scripts or programmatic use):
```bash
echo '<Your Password>' | operator-cli gui set password
```
Note: Be cautious when using this method as the password will be visible in your command history.

Password requirements:
- Minimum 8 characters
- At least 1 lowercase letter
- At least 1 uppercase letter
- At least 1 number
- At least 1 special character from: !@#$%^&*()_+*$

### Advanced Usage

Expand Down
33 changes: 30 additions & 3 deletions src/gui-commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {getInstalledGuiVersion} from './utils/project-data';
import {File} from './utils'
import crypto from 'crypto';
import Ajv from "ajv"
import readline from 'readline';

let config = defaultGuiConfig;

Expand Down Expand Up @@ -133,10 +134,33 @@ export function registerGuiCommands(program: Command) {

setCommand
.command('password')
.arguments('<password>')
.description('Set the GUI server password, requirements: min 8 characters, at least 1 lower case letter, at least 1 upper case letter, at least 1 number, at least 1 special character !@#$%^&*()_+*$')
.option('-h', 'Changes how the password is hashed. For internal use only')
.action((password, options) => {
.action(async (options) => {
let password: string;

if (process.stdin.isTTY) {
// Interactive mode
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});

password = await new Promise<string>((resolve) => {
rl.question('Enter new password: ', (answer) => {
rl.close();
resolve(answer);
});
});
} else {
// Non-interactive mode (e.g., piped input)
password = await new Promise(resolve => {
let data = '';
process.stdin.on('data', chunk => data += chunk);
process.stdin.on('end', () => resolve(data.trim()));
});
}

if (!options.h) {
if (!validPassword(password)) {
console.error(
Expand All @@ -153,7 +177,10 @@ export function registerGuiCommands(program: Command) {
path.join(__dirname, `../${File.GUI_CONFIG}`),
JSON.stringify(config, undefined, 2),
err => {
if (err) console.error(err);
if (err) {
console.error(err);
}
console.log("Password set successfully.");
}
);
});
Expand Down