From de9b50b264cc4a2586ccb962ea6a223cf16824c1 Mon Sep 17 00:00:00 2001 From: edbernar Date: Thu, 8 Aug 2024 17:27:23 +0200 Subject: [PATCH] Site - Added function to password for encrypt it - Doing function for create account --- site/interface/site/login/createConnectDiv.js | 89 +++++++++++++++--- site/interface/site/login/main.js | 6 +- .../Class/__pycache__/User.cpython-310.pyc | Bin 3522 -> 0 bytes .../getPrivateListMessage.cpython-310.pyc | Bin 1081 -> 0 bytes .../getPrivateListUser.cpython-310.pyc | Bin 1125 -> 0 bytes .../__pycache__/login.cpython-310.pyc | Bin 2565 -> 0 bytes .../sendPrivateMessage.cpython-310.pyc | Bin 740 -> 0 bytes websocket-server/typeRequets/login.py | 11 ++- 8 files changed, 83 insertions(+), 23 deletions(-) delete mode 100644 websocket-server/Class/__pycache__/User.cpython-310.pyc delete mode 100644 websocket-server/typeRequets/__pycache__/getPrivateListMessage.cpython-310.pyc delete mode 100644 websocket-server/typeRequets/__pycache__/getPrivateListUser.cpython-310.pyc delete mode 100644 websocket-server/typeRequets/__pycache__/login.cpython-310.pyc delete mode 100644 websocket-server/typeRequets/__pycache__/sendPrivateMessage.cpython-310.pyc diff --git a/site/interface/site/login/createConnectDiv.js b/site/interface/site/login/createConnectDiv.js index f5a6d88..fd75f33 100644 --- a/site/interface/site/login/createConnectDiv.js +++ b/site/interface/site/login/createConnectDiv.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* createConnectDiv.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/07 18:14:53 by edbernar #+# #+# */ -/* Updated: 2024/08/07 22:33:39 by edbernar ### ########.fr */ +/* Updated: 2024/08/08 17:27:14 by edbernar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,12 +14,13 @@ import { userMeInfo, waitForLogin } from "../typeResponse/typeLogin.js"; import { createNotification as CN } from "../notification/main.js"; import { sendRequest } from "../websocket.js"; -function createConnectDiv() +function createConnectDiv(divLogin) { - const divConnect = document.createElement("div"); - const inputLogin = document.createElement("input"); - const inputPass = document.createElement("input"); - const buttonLogin = createButton(inputLogin, inputPass); + const divConnect = document.createElement("div"); + const inputLogin = document.createElement("input"); + const inputPass = document.createElement("input"); + const buttonLogin = createButton(inputLogin, inputPass); + const buttonNewAcc = createButtonNewAcc(divConnect, divLogin); addGlobalBg(); divConnect.setAttribute("id", "connectDiv"); @@ -31,6 +32,7 @@ function createConnectDiv() divConnect.appendChild(inputLogin); divConnect.appendChild(inputPass); divConnect.appendChild(buttonLogin); + divConnect.appendChild(buttonNewAcc); return (divConnect); } @@ -42,25 +44,82 @@ function addGlobalBg() document.body.appendChild(globalBg); } +async function hashPassword(password) +{ + const encoder = new TextEncoder(); + const data = encoder.encode(password); + const hash = await crypto.subtle.digest('SHA-256', data); + const hashArray = Array.from(new Uint8Array(hash)); + const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join(''); + + return (hashHex); +} + function createButton(inputLogin, inputPass) { const loginButton = document.getElementById('loginButton'); const pLoginButton = loginButton.getElementsByTagName('p')[0]; const button = document.createElement("button"); let usernameNode = null; + let hashedPass = null; button.addEventListener('click', () => { - sendRequest("login", {type: "byPass", mail: inputLogin.value, password: inputPass.value}); - waitForLogin().then((token) => { - usernameNode = document.createTextNode(userMeInfo.username); - loginButton.replaceChild(usernameNode, pLoginButton); - CN.new("Connected successfully", "Welcome " + userMeInfo.username, CN.defaultIcon.success); - document.getElementById("loginDiv").remove(); - document.getElementById("globalBg").remove(); - document.cookie = "token={" + token + "}; path=/; Secure; SameSite=Strict; max-age=3600"; + hashPassword(inputPass.value).then((hash) => { + hashedPass = hash; + sendRequest("login", {type: "byPass", mail: inputLogin.value, password: hashedPass}); + waitForLogin().then((token) => { + usernameNode = document.createTextNode(userMeInfo.username); + loginButton.replaceChild(usernameNode, pLoginButton); + CN.new("Connected successfully", "Welcome " + userMeInfo.username, CN.defaultIcon.success); + document.getElementById("loginDiv").remove(); + document.getElementById("globalBg").remove(); + document.cookie = "token={" + token + "}; path=/; Secure; SameSite=Strict; max-age=3600"; + }); + }).catch((err) => { + CN.new("Error", "An error occured while trying to connect", CN.defaultIcon.error); }); }); return (button); } +function createButtonNewAcc(divConnect, divLogin) +{ + const button = document.createElement("button"); + const newDiv = document.createElement("div"); + const inputUsername = document.createElement("input"); + const inputMail = document.createElement("input"); + const inputPass = document.createElement("input"); + const buttonCreate = document.createElement("button"); + + button.innerHTML = "Create a new account"; + newDiv.setAttribute("id", "connectDiv"); + button.addEventListener('click', () => { + inputUsername.setAttribute("type", "text"); + inputUsername.setAttribute("placeholder", "username"); + inputMail.setAttribute("type", "text"); + inputMail.setAttribute("placeholder", "mail"); + inputPass.setAttribute("type", "password"); + inputPass.setAttribute("placeholder", "password"); + buttonCreate.innerHTML = "Create"; + newDiv.appendChild(inputUsername); + newDiv.appendChild(inputMail); + newDiv.appendChild(inputPass); + newDiv.appendChild(buttonCreate); + button.addEventListener('click', createNewAccount); + divConnect.remove(); + divLogin.appendChild(newDiv); + }); + return (button); +} + +function createNewAccount() +{ + const inputUsername = document.getElementsByTagName("input")[0]; + const inputMail = document.getElementsByTagName("input")[1]; + const inputPass = document.getElementsByTagName("input")[2]; + + console.warn("Faire la requete pour creer un compte"); +} + + export { createConnectDiv }; \ No newline at end of file diff --git a/site/interface/site/login/main.js b/site/interface/site/login/main.js index e10cecf..a467f9b 100644 --- a/site/interface/site/login/main.js +++ b/site/interface/site/login/main.js @@ -3,10 +3,10 @@ /* ::: :::::::: */ /* main.js :+: :+: :+: */ /* +:+ +:+ +:+ */ -/* By: edbernar +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/08/07 17:40:15 by edbernar #+# #+# */ -/* Updated: 2024/08/07 22:31:31 by edbernar ### ########.fr */ +/* Updated: 2024/08/08 17:07:12 by edbernar ### ########.fr */ /* */ /* ************************************************************************** */ @@ -35,7 +35,7 @@ function showLoginDiv() { const divLogin = document.createElement("div"); const threeDiv = createThreeDiv(); - const connectDiv = createConnectDiv(); + const connectDiv = createConnectDiv(divLogin); divLogin.setAttribute("id", "loginDiv"); divLogin.appendChild(threeDiv); diff --git a/websocket-server/Class/__pycache__/User.cpython-310.pyc b/websocket-server/Class/__pycache__/User.cpython-310.pyc deleted file mode 100644 index 4a2a25b74076193cf1bd1200a9493433fba68b38..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3522 zcmbVPO>f-B8J-z(ce&rPEIa;48@5H8ECP9zkJF|p0ys`=AlVj;8o}!V#EL^HE3HUn z$hE7*I!GWNdkc_L57N=M9{La3UqPS+`hf!e134II-RGSlDek6+q7-(9GxN^O%jbRO znO9M}-C%hB{HH(c_0|~sJ2lFWg~ogM#kWvMCi#?&OwC7Jx5Y^8vyt^7lR{cgn6ysC z$d>#Q*0Y~s4jcMZmY-tHU!yl*w9ZIKKC&duv_=*Ds?r|SWJOk=u#qEc(m`F9mt|cx zp72paHf0MvP1%+m)Gds3sRZ{B?H_M1nGP5rpT;E_AS7VhmR3yLunIPwpJB)#P4^E`h#3Bn{!tK;M2 zAe23k+Ho-5Q#H8ul&L1F=Rfa=qNxr+l^*wKj^<7`LiRM+W*D&$9KGKH4bAR zD+Hk*^oy-F;pM|X^>0tdaoi_ZZXKVbj^|CnN#c1o2n7d4l{>u3JAB^OHu<>EF_u5{ zUO-38(9m7Up+hauBTfZpc(?ElRu~91jJARCtpY~c%9WG2KqEtOGlTJYS6jIGGkD&; zC-Vl?gPyG_a70y6q|OZMh2x_j6%+ZCE8@5Y&=f7Qsd=6Zrk>}b5t9LZc#E%b`(N`` z_UYQdw=tMMvn&D1DHwFnzqu}Hgak7>+G!fq?VrqU7)k2xt2XPdp6*)UPjxXTsRWyKU z4XlgD`+<51yQ&QoX^kd)I##RT){Cuw0<(A>h4@kc-VXmh*hT!RzLH;9I!c3MJtI=55p4!U+v037r z>~QuNYtC@nT*tBDNGPqG53=K1Bn;x(@gd zu0tzs(VL{8T|+3K4bnOnCE#rWQC2?Dr$Gl(sMiupR=;x|YC}c5n78kR569Dqbd%^X z2q(QCG4{ds3eXoIL-i(mC);Fdu+D()*=a>DpkBeECA5S=i>SK-RoW~q_AbU_ItB#U z24C02F37#6p(>d#=?G~GA$FVA_#1dK|0kiO?m|Zhsk@}1ns!D%b1j9w7%jzk1@AWL z>U*s9k5LJkwn#Yr|rPg|<^fZ-0SrYw+!_u(9tNFRNx1bhe#e&@cAr=lO>+24oEWZ8Unl7Gf-XK3-NX7W-#3YtrV~= zdZ>Re?;<^+Ya=rqC{hCD(hBDGC^DK&?GH3LS@vZ!mnU*0^Fddo#ZC8M{^Omo3Mb)y zW;SrcC_$Dq8&6%jFWkLI9gP!p?PB}l@-i1yu8>(vSJ|OeKcHEeMA98dn+)`ol=mK= zB%fgy`s@!T(+nAHM(NHTx;$^*{b&-FhgQ@h_W-x(#Z|c!m0sgQF%(i~rnFvMqBkwq zZO=>8*bjEc{-NikPO|ImDauLed*1#u+8s|J*65tVkuXC3Lf2hd%NUS0DXPCTbkLXW ziWKRK;6qH&X^4PQQ~E-G0#Za`B=C1t>vuj@9x)bc`X=s(d~Qdt(}0|9@Yc80TGd7- zsFSZ-7dU(;7c8`&Ab|EaNj=W^IV-6=G$mIcIxSE6uqRCJQSqk{@-<2lR=<&MrG&nb zupybH@2T>6LyN1K*T+z=OQEHV4@fsW?ywAZqGhzZp`SfbQ+SGTM3Vjvm zoAp&{>f4sQD0xPixS||V(Y;5rVw&JEo9BOyaH@@}({S32Mr%{s;Xi>!k&MS_Z5*G3 i{vc4H1IzKhv^D~kU4TaNk5N=zni~j)6%<%{S diff --git a/websocket-server/typeRequets/__pycache__/getPrivateListMessage.cpython-310.pyc b/websocket-server/typeRequets/__pycache__/getPrivateListMessage.cpython-310.pyc deleted file mode 100644 index 0d47c91517fca1711aa9f6b882f8f4cbb8003275..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1081 zcma)4&2G~`5Z+xoj?<}d#DTT;o7wT~?94Y4OifJ?SiOVK^{-h%zTshf z;opa_RSkd>PFrM`a0Z&eO`bV6{?e>7+aE1^X0uUiSUh*kb}66Wlkdqc<9R*>(%|$t zDV`g_J7h~wcciyp4MnBpsj$)(N>v*|lf%M7>0W7NZfU_OtvQRO#pR-*&AJTQI_n00 zDEv^H9PXu#t7DFdWqJH+Y8m$_GHr&vj*uBh!o^HZmjQ|mdmXk~1>m#~JoIS@OdQb- z@}kgZF^x$`2aKDc5tAdzGgrxw&5||Jr(HY7`mC+P`D)GOqTXnFul8DPKj?I&3Zwml z*S*8Jg~g@imDRO7cO^bJng);*HH4z6GqUOf4;BcHHKX*PW}_v1WWsG$rM6TkJ-?x; z_ld|0aPddo@$1TI2Ee1!jA}t78^YNL+^7wNDQA0U^HF67VkuYnT==eV4n$1_?w$y5 zDIxcTbdZ*3q8kbDZ-{U^ZO>Ea&Su)2+nt`CX$W6PY+IUOCCy|Ba!@!)CN*iE-2{}E z;OH`d(`AB!w10uEUIM%WZU=NofLF%pECG(M_l=MZ446M-2rSPKp4nsa8nB)UG2&SO03?8!7Itx4e`2DtoB zTJOUzRRCabZI-9gbOIPeDQ|$WXr^gg0X<10v5rN?_RA!^U2X?FYKaFpN~#QC=a~T? SWz_u1tpAkXtzY(h-u?|0mjQzS diff --git a/websocket-server/typeRequets/__pycache__/getPrivateListUser.cpython-310.pyc b/websocket-server/typeRequets/__pycache__/getPrivateListUser.cpython-310.pyc deleted file mode 100644 index 23ce98c31046c3de4cdb5352183a49b168464e5f..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1125 zcmb7C&2AG(5S|%NY$p(Y!p{QQJF-^e9y^I+BZP=ZfFQ84KrX&S?d~3Xl9}$It0%@5 z2axt9kaB<{*L{V31}=R=oKVhtSvYLX1h0@*T4{S!)n8TD)K^t1wY-;Bv?KgMebN89kxbX#foxVNO7XZ2BN~hFTl}utO zX7|U&WN?d+2~CoWW25-OWarDT!?Oi3f8A$gW4%7L`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z~`vqyGVWOP%`ZYtR) z>Ab_TpL8z5F8%{9&DBVsD<{{>Ef@E)gs&?!K`CsVLh&w^5?3K1l+u{N) zl|rF2$?gU;2Y7s4u66@Qw{$wOuhm1|ta%?{nvl0a*h!nR0Yq03^6(q78!B;8g!Nlj*2TV`Yh z{{qi@Xpi3fAM~%tRS^6aM9`P1;({6S&HLW_lK17wt*t78b@JuY@LLI?ua?|g1ju99 z`W^s73{Oym`UoRNSm8bDV@5m3D}IM6^00AO5c7B(@z5UpyNVFlHlJbZ4*>7*@?nY@ zK0q0X(F&)8ku}LkN>*^~8fS!2s22|qU@6BkAYslmWtD4^6;iY+q@X+nQ!TLb0{$ID zQA`&tj53PR@(yTwz+(Z>iO9qB));uXbjrHNM<;dkr^gxUB28j@Mrx$$ai~YSMd2@s>U;T@F3z^2bbK?p^}jyu{7mSikOSoqsqP>_$Uy9 zPgL15YRBXe=(w2jJhj|A6|-P6X7xXJ)is zkV8odQ?ZGrQc`(EQ%N*ePbPuZc@I^{oxIdiJP(w?{3BAkkopn&VyOL*gx3BjxsZvv zPv3^-x(-0Dh~wZIu3~~q`A2Z|=iSmazK@+N@=NW5=*%PeAaar$zX5w7FwSu# QSu)`#7?`F2wOWn*23*I!t^fc4 diff --git a/websocket-server/typeRequets/login.py b/websocket-server/typeRequets/login.py index 31c3657..7e37f34 100644 --- a/websocket-server/typeRequets/login.py +++ b/websocket-server/typeRequets/login.py @@ -3,10 +3,10 @@ # ::: :::::::: # # login.py :+: :+: :+: # # +:+ +:+ +:+ # -# By: edbernar +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2024/08/03 08:10:38 by edbernar #+# #+# # -# Updated: 2024/08/07 22:21:58 by edbernar ### ########.fr # +# Updated: 2024/08/08 16:42:43 by edbernar ### ########.fr # # # # **************************************************************************** # @@ -25,13 +25,14 @@ userList = [ "token": "IDSNCSDAd465sd13215421", "mail": "eddy@ediwor.fr", "password": "ABC123", - "id": 9999999 + "id": 9999999, + 'id42': 123456 }, { "username": "Eddy", "token": "54dsadw8f4a6w5f4a62s4f984fa62f4as65", "mail": "aaaaa", - "password": "aaaaa", + "password": "ed968e840d10d2d313a870bc131a4e2c311d7ad09bdf32b3418147221f51a6e2", # not hashed : aaaaa "id": 2135421 }, { @@ -45,7 +46,7 @@ userList = [ "username": "Mathis", "token": "8cb1qjlfndc12mn2l1mn654xzkkhad54cxz", "mail": "ccccc", - "password": "ccccc", + "password": "6304fbfe2b22557c34c42a70056616786a733b3d09fb326308c813d6ab712ec0", # not hashed : ccccc "id": 2371234 }, {