Skip to content

Commit

Permalink
Merge pull request #58 from novasamatech/fix/password-validation
Browse files Browse the repository at this point in the history
Fix: password validation
  • Loading branch information
sokolova-an authored Feb 6, 2024
2 parents a65694e + 7cca828 commit 2c08344
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 18 deletions.
7 changes: 6 additions & 1 deletion src/common/wallet/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,12 @@ export const resetWallet = (clearLocal: boolean = false) => {

export const initializeWalletFromCloud = (password: string, encryptedMnemonic?: string): string | null => {
if (!encryptedMnemonic) return null;
const mnemonic = AES.decrypt(encryptedMnemonic, password).toString(CryptoJS.enc.Utf8);
let mnemonic;
try {
mnemonic = AES.decrypt(encryptedMnemonic, password).toString(CryptoJS.enc.Utf8);
} catch {
return null;
}

return mnemonic || null;
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/PasswordForm/PasswordForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ export default function PasswordForm({ onSubmit }: PasswordFormProps) {
/>
<BodyText align="left" as="span" className={cnTw('self-start mt-4', VariantStyles[hintColor])}>
<ul className="list-disc space-y-1 ml-5 mb-1">
<li>8 characters minimum</li>
<li>Include at least 1 number (0-9)</li>
<li>Include at least 1 letter (a-z)</li>
<li className={password.length >= 8 ? VariantStyles.success : ''}>8 characters minimum</li>
<li className={cnTw(/\d/.test(password) && VariantStyles.success)}>Include at least 1 number (0-9)</li>
<li className={cnTw(/[a-zA-Z]/.test(password) && VariantStyles.success)}>Include at least 1 letter (A-z)</li>
</ul>
<BodyText align="left" className="text-text-hint">
Make your password stronger - special characters (e.g., @, #, %) and uppercase letters are recommended
Expand Down
1 change: 0 additions & 1 deletion src/screens/dashboard/main/DashboardMain.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { encodeAddress } from '@polkadot/util-crypto';
Expand Down
1 change: 0 additions & 1 deletion src/screens/dashboard/receive/ReceivePage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button, Popover, PopoverContent, PopoverTrigger } from '@nextui-org/react';
Expand Down
1 change: 0 additions & 1 deletion src/screens/gifts/GiftDetailsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect, useState } from 'react';
import { useNavigate, useSearchParams } from 'react-router-dom';
import { WebApp } from '@twa-dev/types';
Expand Down
1 change: 0 additions & 1 deletion src/screens/gifts/GiftPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect, useState } from 'react';
import { Link, useNavigate } from 'react-router-dom';

Expand Down
1 change: 0 additions & 1 deletion src/screens/onboarding/restore/RestoreWallet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';

Expand Down
3 changes: 3 additions & 0 deletions src/screens/settings/BackupPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';

import { useTelegram } from '@/common/providers/telegramProvider';
import { useMainButton } from '@/common/telegram/useMainButton';
import { Paths } from '@/common/routing';
import { BodyText, LinkCard, Plate, TitleText } from '@/components';
import { BACKUP_DATE } from '@/common/utils/constants';

export default function SettingsBackupPage() {
const { BackButton, webApp } = useTelegram();
const { hideMainButton } = useMainButton();
const navigate = useNavigate();
const [backupDate, setBackupDate] = useState('');

useEffect(() => {
hideMainButton();
BackButton?.show();
const callback = () => navigate(Paths.SETTINGS);
BackButton?.onClick(callback);
Expand Down
8 changes: 5 additions & 3 deletions src/screens/settings/password/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,22 @@ export default function ChangePasswordPage() {

useEffect(() => {
const callback = () => {
mainButton.showProgress();
if (password.length < 8) {
setIsPasswordValid(false);

return;
}
webApp?.CloudStorage.getItem(MNEMONIC_STORE, (_err, value) => {
const decryptedMnemonic = initializeWalletFromCloud(password, value);
setIsPasswordValid(Boolean(decryptedMnemonic));
mainButton.hideProgress();

if (decryptedMnemonic) {
navigate(Paths.SETTINGS_NEW_PASSWORD);
}
});
};

if (password.length >= 8) {
if (password.length >= 1) {
mainButton.enable();
addMainButton(callback);
} else {
Expand Down
1 change: 0 additions & 1 deletion src/screens/transfer/AddressPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button, Input } from '@nextui-org/react';
Expand Down
1 change: 0 additions & 1 deletion src/screens/transfer/AmountPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { Button, CircularProgress, Input } from '@nextui-org/react';
Expand Down
2 changes: 1 addition & 1 deletion src/screens/transfer/ConfirmationPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { Divider } from '@nextui-org/react';
Expand Down Expand Up @@ -52,6 +51,7 @@ export default function ConfirmationPage() {
MainButton?.hideProgress();
MainButton?.offClick(mainCallback);
BackButton?.offClick(backCallback);
MainButton?.setText('Continue');
};
}, [selectedAsset]);

Expand Down
1 change: 0 additions & 1 deletion src/screens/transfer/ResultPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

Expand Down
1 change: 0 additions & 1 deletion src/screens/transfer/SelectTokenPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect } from 'react';
import { Link, useNavigate } from 'react-router-dom';

Expand Down
1 change: 0 additions & 1 deletion src/screens/transfer/TrasferPage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use client';
import { useEffect } from 'react';
import { useNavigate } from 'react-router-dom';

Expand Down

0 comments on commit 2c08344

Please sign in to comment.