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

Dev encrypte #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
49 changes: 44 additions & 5 deletions 2048.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
<button id="record">기록하기</button>
<span id="information"></span>
<div id="NotWorkGroup"></div>
<br>&nbsp;&nbsp;&nbsp;&nbsp;<button id="btnup">⇧</button><br><button id="btnlt">⇦</button><button id="btndn">⇩</button><button id="btnrt">⇨</button></div>
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button id="btnup">⇧</button><br><button id="btnlt">⇦</button><button id="btndn">⇩</button><button id="btnrt">⇨</button></div>
<a id="target" style="display: none"></a>
<script src="https://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<script>
let end = 0;
let lose = 0;
Expand Down Expand Up @@ -88,6 +90,36 @@
removedAllEventListener = 1;
};

let el;

function capture(v){
html2canvas(document.body).then(function(canvas) {
if(confirm('스크린샷을 내려 받을까요?')){
el = document.getElementById("target");
el.href = canvas.toDataURL("image/jpeg");
el.download = '2048_complete.jpg';
el.click();
setTimeout(() => {
if(v == 1){
window.opener.postMessage({score:$score.textContent,win:1}, '*');
close();
} else if(v == 0){
window.opener.postMessage({score:$score.textContent,win:0}, '*');
close();
};
},1000);
} else {
if(v == 1){
window.opener.postMessage({score:$score.textContent,win:1}, '*');
close();
} else if(v == 0){
window.opener.postMessage({score:$score.textContent,win:0}, '*');
close();
};
};
});
};

function record(n, name, pw){
console.log('기록 시작');
if(name === null || pw === null) {
Expand Down Expand Up @@ -261,9 +293,11 @@
// login(`${$score.textContent}`);
*/
try {
window.opener.postMessage({score:$score.textContent,win:0}, '*')
close();
/*window.opener.postMessage({score:$score.textContent,win:0}, '*');
close();*/
capture(0);
} catch (error) {
console.log(error);
if (infinity_mode == 0) {
if (confirm('무한모드를 활성화 하시겠습니까?')){
infinity_mode = 1;
Expand Down Expand Up @@ -298,9 +332,14 @@
end = 1;
congratulation_audio.play();
alert('🎉🎉🎉\n축하합니다. 2048을 만들었습니다!\n🎉🎉🎉');
/*if(confirm('스크린샷을 저장 하시겠습니까?')){
capture(1);
} else{
window.opener.postMessage({score:$score.textContent,win:1}, '*')
close();
};*/
capture(1);
// login(n);
window.opener.postMessage({score:$score.textContent,win:1}, '*')
close();
}

$set_fail.addEventListener('click', () => {
Expand Down
216 changes: 182 additions & 34 deletions 2048_Result.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
<div>
<h1 id="info">현재 브라우저의 설정 구획에서 javascript사용을 허용하지 않고있거나 봉사기의 작동이 멈추었을수 있습네다. 따라서 현재 이 창을 정상적으로 렬수 없습니다.</h1>
</div>
<a id="target" style="display: none"></a>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/core.min.js" integrity="sha512-t8vdA86yKUE154D1VlNn78JbDkjv3HxdK/0MJDMBUXUjshuzRgET0ERp/0MAgYS+8YD9YmFwnz6+FWLz1gRZaw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/sha256.min.js" integrity="sha512-fv28nWHTcWfoN3KBd2fs+YWsirQ+L0b/iIRS7HcNDPSAwxy6oSjRrYjQ+OtJoJz0wUKsVcPYgwcZzK04KfHD0A==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
const congratulation_audio = new Audio('congratulation.wav');
const lose_audio = new Audio('2048Lose_Mastering.wav');
Expand Down Expand Up @@ -83,6 +86,7 @@ <h1 id="info">현재 브라우저의 설정 구획에서 javascript사용을 허
console.log(e);
console.log(e.data.score);
console.log(e.data.win);
console.log(e.data.el);
win = e.data.win;
console.log(win);
// startrecord(parseInt(e.data.score));
Expand All @@ -91,7 +95,85 @@ <h1 id="info">현재 브라우저의 설정 구획에서 javascript사용을 허
};
};
window.addEventListener("message", receiveMessage, false);
/*
let encrypted;

function el_down(){
el_value = confirm('스크린샷을 내려받을까요?');
if(el_value){
el_here = document.getElementById("target");
el_here.href = el;
el_here.download = '2048_complete.jpg';
el_here.click();
}
}*/
function start_encrypte(v){
console.log('encrypte start.');
encrypted = undefined;
console.log('reset \'encrypted\(var\)\'.');
encrypted = CryptoJS.SHA256(v);
encrypted = String(encrypted);
console.log(encrypted);
};
let encrypted_login;
let encrypted_login_id;
let encrypted_login_pw;
let encrypted_record;

function cookie_login(n,v){
start_encrypte(n);
n = encrypted;
encrypted_login_id = n;
start_encrypte(v);
v = encrypted;
encrypted_login_pw = v;
start_encrypte(n+v);
encrypted_login = encrypted;
console.log(encrypted_login);
console.log(encrypted_login_id);
console.log(encrypted_login_pw);
};

function cookie_record(n,v){
start_encrypte(n);
n = encrypted;
v = start_encrypte(v);
start_encrypte(n+v);
encrypted_record = encrypted;
console.log(encrypted_record);
};
let cookie_temp_login;
let cookie_temp_record;
function cookie(o,p,n,v){ // o=작업, p=조회와 작성 구분, n=name, v=value(login시 pw, record시 점수)
if(o == 'login'){
cookie_login(n,v);
// cookie_temp_login = 1;
if(p == 'c' && window.localStorage.getItem(encrypted_login_id) == encrypted_login){ // 체크
cookie_temp_login = true;
console.log('true');
} else if(p == 'w'){ // 작성
window.localStorage.setItem(encrypted_login_id, encrypted_login);
};
} else if(o == 'record'){
cookie_record(n,v);
// cookie_temp_record = 1;
if(p == 'c' && window.localStorage.getItem(encrypted_record) == true){ // 체크
cookie_temp_record = window.localStorage.getItem(encrypted_record);
// cookie_record(encrypted_login,cookie_temp_record);
if(window.localStorage.getItem(name) == encrypted_record){
cookie_temp_record = true;
console.log('true');
} else{
cookie_temp_record = false;
console.log('true');
};
} else if(p == 'w'){ // 작성
cookie_record(encrypted_login,score);
window.localStorage.setItem(encrypted_record,score);
window.localStorage.setItem(name,encrypted_record);
};
};
}
function startrecord(n) {
if (win == 0) { // Lose
document.write(n+'점 으로 패배!');
Expand All @@ -110,77 +192,132 @@ <h1 id="info">현재 브라우저의 설정 구획에서 javascript사용을 허
};
login(n);
};
let name;
let pw;
let pw1;

let restart_function = 0
function login(n){
console.log(n+'점을 기록.');
let game_window_close = 0
setTimeout(() => {
const name = prompt('당신의 닉네임을 작성해주세요.');
// let input_data_empty = 0;
name = prompt('당신의 닉네임을 작성해주세요.');
if(name == null) {
alert('기록이 취소되었습니다.');
return;
} else if(name === '') {
login(n);
// input_data_empty = 1;
return;
};
const pw = prompt('비밀번호를 입력해주세요');
pw = prompt('비밀번호를 입력해주세요');
if(pw == null) {
alert('기록이 취소되었습니다.');
return;
} else if(pw === '') {
login(n);
// input_data_empty = 1;
return;
};
/*if(input_data_empty == 1) {
console.log('empty data');
return;
};*/
console.log(pw);
if(name){
console.log('닉네임: ' + name);
let name_list = false;
if(window.localStorage.getItem(name)){
name_list = window.localStorage.getItem(name);
console.log(String(name_list)+String(pw));
start_encrypte(name);
let encrypted_name = encrypted;
start_encrypte(pw);
let encrypted_pw = encrypted;
start_encrypte(name+pw);
let encrypted_id = encrypted;
cookie('login','c',name,pw);
if(window.localStorage.getItem(encrypted_name)){
name_list = window.localStorage.getItem(encrypted_name);
console.log(name_list+pw);
console.log(name_list+encrypted_pw);
if(name_list == true){
console.log('가입필요.');
pw1 == prompt('신규 가입중...\n비밀번호를 다시 한번 입력해주세요');
if(pw == pw1){
window.localStorage.setItem(name, pw);
console.log('완료');
} else if (pw1 == window.localStorage.getItem(pw)) {
alert('사용 불가능한 비밀번호입니다.');
pw1 == prompt('신규 가입중...\n비밀번호를 다시 한번 입력해주세요.');
if(pw1 == null){
console.log('가입 취소됨.')
restart_function = 1;
return;
} else if(pw == pw1){
/*if (window.localStorage.getItem(pw1) == true) {
alert('사용 불가능한 비밀번호입니다.');
restart_function = 1;
return;
} else{
// window.localStorage.setItem(name, pw);
cookie('login','w',name,pw);
console.log('완료');
};*/
cookie('login','w',name,pw);
console.log('완료');
} else{
console.log('비밀번호 틀림');
restart_function = 1;
alert('비밀번호가 틀렸습니다.');
restart_function = 1
return;
if(true){
return;
};
};
} else if(name_list == pw){
} else if(window.localStorage.getItem(encrypted_login_id) == encrypted_login){
console.log('기록 되어있는 닉네임.');
} else{
console.log('비밀번호 틀림');
restart_function = 1;
alert('비밀번호가 틀렸습니다.');
restart_function = 1
return;
// return;
};
} else {
console.log('신규');
const pw1 = prompt('신규 가입중...\n비밀번호를 입력해주세요');
if(pw == pw1){
window.localStorage.setItem(name, pw);
console.log('완료');
alert('가입이 완료되었습니다. 본 계정은 본 기기에 한하여 사용이 가능합니다.')
} else{
pw1 = prompt('신규 가입중...\n비밀번호를 다시 한번 입력해주세요.');
start_encrypte(pw1);
let encrypted_temp1 = encrypted;
start_encrypte(pw);
let encrypted_temp2 = encrypted;
console.log(`${encrypted_temp1}, ${encrypted_temp2}`);
if(pw1 == null){
console.log('가입 취소됨.')
restart_function = 1;
// return;
} else if(window.localStorage.getItem(encrypted_temp1) == true){
alert('사용 불가능한 비밀번호입니다.');
restart_function = 1;
return;
} else if(encrypted_temp1 == encrypted_temp2){
// window.localStorage.setItem(name, pw);
cookie('login', 'w', name, pw);
console.log('완료');
alert('가입이 완료되었습니다. 본 계정은 본 기기에 한하여 사용이 가능합니다.')
} else {
console.log('비밀번호 틀림');
alert('비밀번호가 틀렸습니다.');
restart_function = 1;
}
alert('비밀번호가 틀렸습니다.');
return;
};
};
if(restart_function == 1){
restart_function = 0;
console.log('restart!');
login(n);
}
else{
} else {
record(n, name, pw);
};
// return;
} else{
} else {
return;
}
};
if(restart_function == 1){
restart_function = 0;
console.log('restart!');
login(n);
};
}, 100);;
}
/*if(restart_function == 1){
Expand All @@ -194,26 +331,37 @@ <h1 id="info">현재 브라우저의 설정 구획에서 javascript사용을 허
console.log('취소!');
return;
};
if(!window.localStorage.getItem(pw)) {
// start_encrypte(pw);
if(!window.localStorage.getItem(encrypted)) {
console.log('첫번째 기록!');
window.localStorage.setItem(pw,n);
// window.localStorage.setItem(pw,n);
start_encrypte(pw);
cookie('record','w',pw,n);
console.log('기록 완료!');
alert('기록을 성공적으로 끝마쳤습니다!');
} else{
console.log('이전의 기록 발견!');
const prev = window.localStorage.getItem(pw);
start_encrypte(pw);
cookie('login','c',name,pw);
cookie_record(encrypted_login,score);
const prev = window.localStorage.getItem(encrypted_record);
if(prev < n){
window.localStorage.setItem(pw,n);
// window.localStorage.setItem(pw,n);
cookie('record','w',pw,n);
console.log('최고기록 달성!');
alert(n+'점\n최고기록 달성!\n축하드립니다!!🎉🎉');
console.log('완료');
alert('기록을 성공적으로 끝마쳤습니다!');
} else if(prev > n){
const prev_temp = prev-n;
alert(prev_temp+'점 차이로 아쉽게 실패!');
const want_record = confirm('기록을 갱신 하시겠습니까?');
if(want_record){
if(confirm('기존기록은 삭제 됩니다.\n그래도 하시겠습니까?')){
window.localStorage.setItem(pw,n);
console.log('완료')
// window.localStorage.setItem(pw,n);
cookie('record','w',pw,n);
console.log('완료');
alert('기록을 성공적으로 끝마쳤습니다!');
} else{
console.log('cancled');
};
Expand Down
Loading