TIL
-
WEB) JWT 토큰인증 - 세션 vs 쿠키 vs 토큰TIL 2024. 1. 9. 15:53
JWT 정의) ㄴJSON WEB TOKEN ㄴToken 기법의 한 종류(웹표준) ㄴJSON형태로 되어있어서. 값의 관리가 쉬움 ㄴ조작여부 판단이 간단해서 웹 표준으로 삼고있음 -구조 ㄴToken이라는 것 자체가 그냥 특정한 폼을 가진 String "header":{ token의 설정 정보(발행자, 만료시간, 종류 등) }, "payload":{ 개발자가 Token에 넣고 싶은 값 }, "signature" : 비밀키로 암호화된 header + payload ㄴ이렇게 3가지의 Key를 String으로 변환해서 저장한게 Token -jwt가 어떻게 FE 조작을 막는가?) 1. header와 payload를 각각 String으로 만듬 2. A.B 의 형태로 저장 3. A.B를 비밀키로 암호화해서 C라고 저장 ..
-
[web] 쿼리스트링, 패스파라미터(시멘틱 URL)TIL 2023. 12. 13. 15:40
쿼리스트링) url 끝에 데이터 값을 전달. 쓰는이유 : 같은 path에 다른 데이터값을 줘서 페이지가 동적으로 작동할 수 있게, 상황에따라 다른 정보를 보여줄수 있게 하기 위함이다 사용방법) path뒤에 ?data1="값1"&data2="값2" 와 같은 방 식으로 전해준다 http://index.html/idx=9 밑줄친 부분이 쿼리스트링 api 에서 그 전달 받은 값을 받아서 쓰는법) http://index.html/article?articleIdx=10 를 전달받았다면) app.get("/article", (req, res) => { const articleIdx = req.query.articleIdx; // 변수에 10 할당 }) ㄴ쿼리스트링(articleIdx=10)을 프로퍼티로 갖는다. 그래..
-
문자열에서 숫자만 남기기TIL 2023. 11. 13. 20:32
전화번호를 입력받을때 010 0000 0000 와 같이 입력받아야하는데, 010-0000-0000와 같이 입력받은 경우 생년월일,날짜를 20041010와 같이 입력받아야하는데, 2004/10/10, 2004-10-10등과 같이 입력받은 경우 입력받은 값에서 불필요한 문자들을 제거하여 원하는 형식으로 만들어야 한다. 입력받은 값들을 다음과 같이 변환해야하는 경우 010-0000-0000 -> 010 0000 0000 010.0000.0000 -> 010 0000 0000 2004-12-12 -> 2004 12 12 2004/12/12 -> 2004 12 12 str.replaceAll("[^0-9]","") // *숫자가 아닌 것들을 모두 제거
-
[TIL]이메일 형식 확인TIL 2023. 11. 13. 19:16
사용자로부터 입력받은 값이 이메일형식이 맞는지 확인하기 이메일 정규 표현식 ㄴ ^[A-z0-9]+@[A-z0-9]+\\.[a-z]{2,3}$ ^ : 문자열 시작 [A-z0-9]+ : 영문자,숫자가 1개이상 @ : @하나 존재해야함 [A-z0-9]+ : 영문자,숫자가 1개이상 \\. : .(점)하나 존재해야함. 혼자쓸수없어서 \(이스케이프) 같이씀 [a-z]{2,3} : a-z문자가 2~3개 $: 문자열 끝 java 코드) import java.util.regex.Pattern String pattern = "^[A-z0-9]+@[A-z0-9]+\\.[a-z]{2,3}$"; // 이메일 형식 정규표현식 String idValue = request.getParameter("id_value"); // 사용자에..
-
[TIL] 자료구조5 - 해시 테이블TIL 2023. 5. 28. 19:27
해시 테이블 -가장 유용한 자료 구조중 하나 1. 가게에서 물건의 가격 찾을때 빨리 찾는 순서는? -> 모든 가격표를 외운 알바생 > 정렬된리스트 > 정렬되지 않은 리스트 2. 가게에서 물건의 가격 찾을때 빨리찾는 순서와 시간복잡도는? -> 모든 가격표를 외운 알바생(O(1)) > 정렬된리스트(이진 탐색) (O(log n)) > 정렬되지 않은 리스트(단순 탐색)(O(1)) 가격을 외운 알바생을 만드는 법 : 해시 함수 해시테이블은 언제 사용해야할까?-> 해싱은 특정 데이터가 "들어온 순서 상관 없이" 삽입, 삭제, 검색이 자주 발생하는 경우에 사용하기에 좋다. 해시함수 조건 1. 일관성을 가져야한다 같은 문자를 넣었을때는 항상 같은 값이 나와야만 한다 ex) apple을 넣..