Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove useless code and unify the methodology #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 6 additions & 14 deletions website/js/PasskyAPI.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@
});
}

static createAccount(server, username, password, email){
static createAccount(server, username, authPassword, email){
return new Promise((resolve, reject) => {
if(!Validate.url(server)) return reject(1001);
if(!Validate.email(email)) return reject(1007);
if(!Validate.username(username)) return reject(1005);
if(!Validate.password(password)) return reject(1006);
if(!Validate.password(authPassword)) return reject(1006);

let data = new FormData();
data.append("email", email);

let headers = new Headers();
headers.append('Authorization', 'Basic ' + btoa(username + ":" + password));
headers.append('Authorization', 'Basic ' + btoa(username + ":" + authPassword));

fetch(server + "?action=createAccount", {
method: "POST",
Expand All @@ -149,18 +149,18 @@
});
}

static getToken(server, username, password, otp = "", encrypted = true){
static getToken(server, username, authPassword, otp = ""){
return new Promise((resolve, reject) => {
if(!Validate.url(server)) return reject(1001);
if(!Validate.username(username)) return reject(1005);
if(!Validate.password(password)) return reject(1006);
if(!Validate.password(authPassword)) return reject(1006);
if(!Validate.otp(otp)) return reject(1002);

let data = new FormData();
data.append("otp", otp);

let headers = new Headers();
headers.append('Authorization', 'Basic ' + btoa(username + ":" + password));
headers.append('Authorization', 'Basic ' + btoa(username + ":" + authPassword));

fetch(server + "?action=getToken", {
method: "POST",
Expand All @@ -172,14 +172,6 @@
}).then((response) => {
try{
let data = JSON.parse(response);
if(!encrypted && data.passwords != null){
for(let i = 0; i < data.passwords.length; i++){
data.passwords[i].website = XChaCha20.decrypt(data.passwords[i].website, password);
data.passwords[i].username = XChaCha20.decrypt(data.passwords[i].username, password);
data.passwords[i].password = XChaCha20.decrypt(data.passwords[i].password, password);
data.passwords[i].message = XChaCha20.decrypt(data.passwords[i].message, password);
}
}
return resolve(data);
}catch(error){
return reject(1000);
Expand Down