summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClayton <nrootconauto@gmail.com>2023-02-28 15:51:27 -0500
committerClayton <nrootconauto@gmail.com>2023-02-28 15:51:27 -0500
commitaadaa27fc5a97d0dba4470b1d191ef0edf61dd13 (patch)
tree87fc7d4b3a1739a94279d047f23a22b0d8d4d19f
parent95e3143eaf9455feeff9e60a3a584ce15b8cd118 (diff)
Added password change feature
-rw-r--r--T/Registry.HC.Zbin409 -> 408 bytes
-rw-r--r--T/Server/gen_html.HC5
-rw-r--r--T/Server/run.HC1
-rw-r--r--T/Server/touch_all.HC2
-rw-r--r--T/Server/users.HC55
5 files changed, 61 insertions, 2 deletions
diff --git a/T/Registry.HC.Z b/T/Registry.HC.Z
index aa91634..8f496d7 100644
--- a/T/Registry.HC.Z
+++ b/T/Registry.HC.Z
Binary files differ
diff --git a/T/Server/gen_html.HC b/T/Server/gen_html.HC
index 96c7d3e..d8fccdc 100644
--- a/T/Server/gen_html.HC
+++ b/T/Server/gen_html.HC
@@ -437,7 +437,10 @@ U0 Post(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,CHashTable
} else if(!StrICmp(url->abs_path,WIKI_ADMIN)) {
AdminPanelPost(srv,stream,url,req,tab);
goto fin;
- }
+ } else if(!StrICmp(url->abs_path,WIKI_CHANGE_PASS)){
+ ChangePassPost(srv,stream,url,req,tab);
+ goto fin;
+ }
FileGet(srv,stream,url,req);
fin:
EndHttpRequest(stream);
diff --git a/T/Server/run.HC b/T/Server/run.HC
index f16a1ad..cdaea8a 100644
--- a/T/Server/run.HC
+++ b/T/Server/run.HC
@@ -32,6 +32,7 @@ extern Bool UserPrivCheck(CServer *srv,CDyadStream *stream,CURL *url,CHTTPReques
extern Bool FileIsSalted(U8 *file);
extern Bool CurrentUserIsAdmin();
#define WIKI_EDIT "/EDIT"
+#define WIKI_CHANGE_PASS "/CHPASS"
#define WIKI_ROOT "/Wiki"
#define WIKI_NAME "TempleOS Tiki"
#define WIKI_HOME "/"
diff --git a/T/Server/touch_all.HC b/T/Server/touch_all.HC
index 2421aa4..f97ca12 100644
--- a/T/Server/touch_all.HC
+++ b/T/Server/touch_all.HC
@@ -6,7 +6,7 @@ U0 TouchAll() {
I64 len;
for(cur=root;cur;cur=cur->next) {
ftxt=FileRead(cur->full_name,&len);
- BackupFile(cur->full_name+StrLen(to_trim),ftxt,len,"root");
+ BackupFile(cur->full_name+StrLen(to_trim),ftxt,len,"root","c");
Free(ftxt);
}
DirEntryDel(root);
diff --git a/T/Server/users.HC b/T/Server/users.HC
index 9ad2358..68ab782 100644
--- a/T/Server/users.HC
+++ b/T/Server/users.HC
@@ -354,6 +354,51 @@ U0 DeleteSelfPost(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,C
}
+U0 ChangePassPost(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,CHashTable *tab) {
+ CHashGeneric *cur=HashFind("old",tab,-1),*new=HashFind("new",tab,-1),*new2=HashFind("new2",tab,-1);
+ if(!UserPrivCheck(srv,stream,url,req,"none")) {
+ return;
+ }
+ LockUsers;
+ CSrvUser *u=GetCurrentUser;
+ U8 *t;
+ CConnection *con=Fs->user_data;
+ con->response_code=200;
+ StrCpy(con->response_mime,"text/html");
+ if(!cur||!new||!new2) {
+ WikiHeader(stream,NULL,"Internal Error!!!",0);
+ WriteLn(stream,,"<H2>Password not changed!!!</H2>");
+ WikiFooter(stream,NULL,url);
+ goto fin;
+ }
+ t=FNV64Str(cur->user_data1);
+ if(StrCmp(u->pass_hash,t)) {
+ Free(t);
+ WikiHeader(stream,NULL,"Current password is incorrect!!!",0);
+ WriteLn(stream,,"<H2>Password not changed!!!</H2>");
+ WriteLn(stream,,"<P>Passwords don't match</P>");
+ WikiFooter(stream,NULL,url);
+ goto fin;
+ }
+ Free(t);
+ if(StrCmp(new->user_data1,new2->user_data1)) {
+ WikiHeader(stream,NULL,"Passwords dont match!!!",0);
+ WriteLn(stream,,"<H2>Password not changed!!!</H2>");
+ WriteLn(stream,,"<P>You entered your old password wrong!</P>");
+ WikiFooter(stream,NULL,url);
+ goto fin;
+ }
+ WikiHeader(stream,NULL,"Password Change Successful!!!",0);
+ WriteLn(stream,,"<H2>Yay!!!</H2>");
+ t=FNV64Str(new->user_data1);
+ StrCpy(u->pass_hash,t);
+ Spawn(&UpdateUserRegistry,,,0);
+ Free(t);
+ WikiFooter(stream,NULL,url);
+fin:
+ UnlockUsers;
+}
+
U0 LogoutPost(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req,CHashTable *tab) {
LockUsers;
CSrvUser *cur=GetCurrentUser;
@@ -497,6 +542,16 @@ U0 UserPannelGet(CServer *srv,CDyadStream *stream,CURL *url,CHTTPRequest *req) {
WriteLn(stream,,"<FORM ACTION=\"" WIKI_LOGOUT "\" CLASS=\"form-group\" METHOD=\"POST\">");
WriteLn(stream,,"<INPUT TYPE=\"submit\" VALUE=\"Logout\">");
WriteLn(stream,,"</FORM>");
+ WriteLn(stream,,"<H3>Change Password</H3>");
+ WriteLn(stream,,"<FORM ACTION=\"" WIKI_CHANGE_PASS "\" CLASS=\"form-group\" METHOD=\"POST\">");
+ WriteLn(stream,,"<LABEL FOR=\"old\">Old Password</LABEL>");
+ WriteLn(stream,,"<INPUT NAME=\"old\" TYPE=\"password\">");
+ WriteLn(stream,,"<LABEL FOR=\"new\" >Password</LABEL>");
+ WriteLn(stream,,"<INPUT NAME=\"new\" TYPE=\"password\">");
+ WriteLn(stream,,"<LABEL FOR=\"new2\" >Confirm New Password</LABEL>");
+ WriteLn(stream,,"<INPUT NAME=\"new2\" TYPE=\"password\">");
+ WriteLn(stream,,"<INPUT TYPE=\"submit\" VALUE=\"Change password\">");
+ WriteLn(stream,,"</FORM>");
if(user->flags&UF_ADMIN){
WriteLn(stream,,"<H2>Admin Panel</H2>");
WriteLn(stream,,"<P>Click a User to edit thier flags,then click the submit "