Skip to content

Commit

Permalink
Add retries if passwords dont match
Browse files Browse the repository at this point in the history
  • Loading branch information
keeramis committed Feb 3, 2025
1 parent 4c7177c commit f6a6fa5
Showing 1 changed file with 65 additions and 53 deletions.
118 changes: 65 additions & 53 deletions src/cmd/setup-tachyon.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,39 +366,39 @@ Welcome to the Particle Tachyon setup! This interactive command:
}

async _getSystemPassword() {
const questions = [
{
type: 'password',
name: 'password',
message: 'Password for the system account:',
validate: (value) => {
if (!value) {
return 'Enter a password for the root account';
}
return true;
}
},
{
type: 'password',
name: 'passwordConfirm',
message: 'Re-enter the password for the root account:',
validate: (value) => {
if (!value) {
return 'You need to confirm the password';
}
return true;
let attempts = 0;
const maxAttempts = 3;

while (attempts < maxAttempts) {
const questions = [
{
type: 'password',
name: 'password',
message: 'Password for the system account:',
validate: (value) => value ? true : 'Enter a password for the root account'
},
{
type: 'password',
name: 'passwordConfirm',
message: 'Re-enter the password for the root account:',
validate: (value) => value ? true : 'You need to confirm the password'
}
];

const res = await this.ui.prompt(questions);

if (res.password === res.passwordConfirm) {
return res.password;
}

attempts++;
this.ui.write(`Passwords do not match.${os.EOL}`);

if (attempts === maxAttempts) {
throw new Error('Passwords do not match. Restart the setup process.');
}
];
const res = await this.ui.prompt(questions);

//check if the passwords match
if (res.password !== res.passwordConfirm) {
throw new Error('Passwords do not match. Please try again.');
}

return res.password;
}
}

async _getWifi() {
const question = [
Expand All @@ -418,31 +418,43 @@ Welcome to the Particle Tachyon setup! This interactive command:
}

async _getWifiCredentials() {
const questions = [
{
type: 'input',
name: 'ssid',
message: 'Enter your WiFi SSID:'
},
{
type: 'password',
name: 'password',
message: 'Enter your WiFi password:'
},
{
type: 'password',
name: 'passwordConfirm',
message: 'Re-enter your WiFi password:'
},
];
const res = await this.ui.prompt(questions);

if (res.password !== res.passwordConfirm) {
throw new Error('Passwords do not match. Please try again.');
let attempts = 0;
const maxAttempts = 3;

while (attempts < maxAttempts) {
const questions = [
{
type: 'input',
name: 'ssid',
message: 'Enter your WiFi SSID:'
},
{
type: 'password',
name: 'password',
message: 'Enter your WiFi password:'
},
{
type: 'password',
name: 'passwordConfirm',
message: 'Re-enter your WiFi password:'
}
];

const res = await this.ui.prompt(questions);

if (res.password === res.passwordConfirm) {
return { ssid: res.ssid, password: res.password };
}

attempts++;
this.ui.write(`WiFi passwords do not match.${os.EOL}`);

if (attempts === maxAttempts) {
throw new Error('WiFi passwords do not match. Restart the setup process.');
}
}

return { ssid: res.ssid, password: res.password };
}


async _getKeys() {
let question = [
Expand Down

0 comments on commit f6a6fa5

Please sign in to comment.