Skip to content

Commit

Permalink
sdp-tech#78 feat: add password validation
Browse files Browse the repository at this point in the history
  • Loading branch information
eujin-shin committed Jul 10, 2024
1 parent ac85b71 commit 69326ec
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/common/InputView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ interface InputViewProps extends InputBoxProps {
info?: string;
caption?: {
none?: false | string;
default?: false | string;
invalid?: false | string;
};
}
Expand Down Expand Up @@ -73,6 +74,9 @@ const InputView = ({
{value === '' && caption?.none && (
<Caption11M style={{ color: GRAY }}>{caption.none}</Caption11M>
)}
{caption?.default && (
<Caption11M style={{ color: GRAY }}>{caption.default}</Caption11M>
)}
{caption?.invalid && (
<Caption11M style={{ color: PURPLE }}>{caption.invalid}</Caption11M>
)}
Expand Down
26 changes: 19 additions & 7 deletions src/components/Auth/BasicForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,26 @@ export default function BasicForm({ navigation, route }: FormProps) {
d: false,
});
const [checkPw, setCheckPw] = useState('');
const [domainOpen, setDomainOpen] = useState(false);
const [invalidPw, setInvalidPw] = useState<undefined | boolean>(undefined);
const [modalOpen, setModalOpen] = useState(false);
const [splash, setSplash] = useState(false);

const request = Request();
const passwordRegExp = new RegExp(
'^(?=.*[a-zA-Z])(?=.*[!@#$%^*+=-])(?=.*[0-9]).{8,15}$',
);

const passwordValidation = (callback: () => void) => {
if (passwordRegExp.exec(form.password)) {
callback();
} else {
Alert.alert('비밀번호가 올바르지 않습니다.');
setForm(prev => {
return { ...prev, password: '' };
});
setCheckPw('');
}
};

const handleSubmit = async () => {
const params = {
Expand Down Expand Up @@ -199,11 +214,8 @@ export default function BasicForm({ navigation, route }: FormProps) {
style={{ height: 44, marginTop: 8 }}
secure={true}
caption={{
none: '비밀번호 조건',
invalid:
form.password !== '' &&
form.password.length < 7 &&
'비밀번호가 올바르지 않습니다.',
default:
'숫자, 영문, 특수문자를 하나 이상 포함해 8자 이상 16자 이하로 설정해 주세요.',
}}
/>

Expand Down Expand Up @@ -303,7 +315,7 @@ export default function BasicForm({ navigation, route }: FormProps) {
}
value="다음"
pressed={false}
onPress={handleSubmit}
onPress={() => passwordValidation(handleSubmit)}
style={{
width: '75%',
alignSelf: 'center',
Expand Down

0 comments on commit 69326ec

Please sign in to comment.