Compare commits

..
12 Commits
Author SHA1 Message Date
whoswhip ae3b96d7e0 Update README.md
no longer using react & vite, switching back to pure html
2025-01-16 17:36:51 -05:00
whoswhip 6e95ae595a Update README.md 2025-01-15 23:20:41 -05:00
whoswhip 517a82d058 Enhance password security and simplify configuration
Turns out I should've looked into the bcrypt hashing algorithm a bit more, turns out you can have a unique salt per hash and can just use a verify method

- Remove `salt` and `smallerSalt` fields from `Program` class.
- Replace `Password` with `PasswordHash` in `Paste` and `PrivatePaste` classes.
- Generate a new salt for each password hash.
- Use `BCrypt.Net.BCrypt.Verify` for password verification.
- Remove `salt` and `smallerSalt` logic from `config.json`.
- Ensure consistent use of `PasswordHash` for storing and verifying passwords.
2024-10-29 17:11:43 -04:00
whoswhip 46615aba5b Refactor endpoints and update HTML for new API
Simplified /archive endpoint to return static HTML without dynamic content or database queries. Refactored CreatePaste method to accept a Paste object and conditionally write compressed or uncompressed content based on size. Added new /api/pastes/get endpoint for fetching paginated pastes in JSON format.

Updated archives.html to remove dynamic placeholders, using JavaScript for fetching and displaying pastes, and handling user authentication and pagination. Improved index.html with new font family and font weight for buttons. Updated paste.html to truncate long paste titles for display.

Removed unused using directive in Turnstile.cs. Updated Program.cs to include new API endpoint and refactored CreatePaste method.
2024-10-25 16:40:26 -04:00
whoswhip 59c609e7c1 Merge branch 'master' of https://github.com/whoswhip/Sharpbin 2024-10-19 15:21:56 -04:00
whoswhip ada51d5c56 Move install script 2024-10-19 15:21:52 -04:00
whoswhip c158cde86d Update README.md 2024-10-19 15:19:33 -04:00
whoswhip 38d25d785e Merge branch 'master' of https://github.com/whoswhip/Sharpbin 2024-10-19 15:19:14 -04:00
whoswhip 410172f922 Update rate limiters, endpoints, and UI styles
Added a new "fixed-xl" rate limiter policy with a permit limit of 16 and applied it to several endpoints. Replaced "fixed-bigger" with "fixed-xl" on some endpoints. Introduced a new POST endpoint `/api/pastes/admin/change-id` for changing paste IDs, including authorization checks and error handling. Enhanced logging for paste edits to include paste ID and user info. Adjusted rate limiting policies for various endpoints to use "fixed-bigger" instead of "fixed".

Modified UI styles: changed `.nav-div` margin-top in `index.html` from 10px to 1.5px, increased `backdrop-filter` blur in `paste.html` and `privatepaste.html` from 2.5px to 5px, added a border to `.input-wrapper-container` in `paste.html` and `privatepaste.html`, removed the title attribute from `<h1>` in `privatepaste.html`, simplified JSON parsing in `fetchInfo` function, removed redundant localization code, and updated `.user-a` class to use `:any-link` pseudo-class.

Various minor adjustments to improve code readability and maintainability.
2024-10-19 15:19:09 -04:00
whoswhip b872de29d2 Update README.md 2024-10-19 00:56:34 -04:00
whoswhip c90bd84ad7 Update README.md 2024-10-19 00:56:02 -04:00
whoswhip eb542342c9 Hot fixes, changed every single writeasjsonasync to writeasync cause it would bug some other stuff,fixed the authentication api which for some reason redirected to lost paste???? 2024-10-19 00:46:19 -04:00
11 changed files with 438 additions and 270 deletions
+328 -223
View File
File diff suppressed because it is too large Load Diff
-2
View File
@@ -1,6 +1,4 @@
using Newtonsoft.Json.Linq;
using System;
using System.Net.Http;
using System.Text;
namespace Sharpbin
+3 -3
View File
@@ -153,7 +153,7 @@
}).then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`${result.message} for ${reason}`);
} else {
@@ -174,7 +174,7 @@
}).then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`${result.message} for ${reason}`);
} else {
@@ -199,7 +199,7 @@
}).then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`${result.message} to ${result.password}`);
navigator.clipboard.writeText(result.password);
+69 -7
View File
@@ -13,10 +13,13 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
<div class="nav-hamburger-menu">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list" viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
<svg xmlns="http://www.w3.org/2000/svg" width="56" height="56" fill="currentColor" class="bi bi-list"
viewBox="0 0 16 16" id="hamburger-button" style="cursor: pointer;">
<path fill-rule="evenodd"
d="M2.5 12a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5m0-4a.5.5 0 0 1 .5-.5h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5" />
</svg>
@@ -24,7 +27,9 @@
<a href="/">home</a>
<a href="/pastes">recent pastes</a>
<a href="/archive">archive</a>
{html}
<a href="login" id="login-signup-btn" style="display: none;" >login</a>
<a href="sign-up" id="login-signup-btn" style="display: none;">sign up</a>
<a href="dash" id="dash-btn" style="display: none;">dashboard</a>
</div>
</div>
<div class="container-wrapper">
@@ -32,18 +37,73 @@
<h1>paste archive</h1>
<input type="text" placeholder="search" class="text-input" oninput="search()">
<div class="pastes-wrapper">
{pastes}
Loading...
</div>
<div class="buttons-wrapper">
<a class="arrow-button" href="/archive?page={backpagenum}">&lt;</a>
<p>{currentpagenum}/{totalpages}</p>
<a class="arrow-button" href="/archive?page={pagenum}">></a>
<a class="arrow-button" id="back-page">&lt;</a>
<p id="page-count"></p>
<a class="arrow-button" id="next-page">></a>
</div>
</div>
</div>
</body>
<script>
let searchTimeout;
let pagenum = 1;
function authenticate() {
fetch('/api/accounts/authenticate')
.then(response => response.json())
.then(data => {
if (data.message == "Authenticated") {
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'none';
});
document.getElementById('dash-btn').style.display = 'block';
}else{
document.querySelectorAll("#login-signup-btn").forEach(element => {
element.style.display = 'block';
});
}
});
}
function getPastes() {
fetch(`/api/pastes/get`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
page: pagenum
})
})
.then(response => response.json())
.then(data => {
const pastesWrapper = document.querySelector('.pastes-wrapper');
const pageCount = document.getElementById('page-count');
pastesWrapper.innerHTML = '';
pageCount.innerHTML = `${pagenum}/${data.pages}`;
if (data.pastes.length === 0) {
pastesWrapper.innerHTML = '<h1>no pastes found</h1>';
return;
}
data.pastes.forEach(paste => {
title = paste.title.length > 30 ? paste.title.substring(0, 30) + '...' : paste.title;
pastesWrapper.innerHTML += `<a href="/${paste.id}" title="${paste.title}"><li>${title} ${paste.date} ${paste.size}</li></a>`;
});
});
}
document.getElementById('back-page').addEventListener('click', function () {
if (pagenum > 1) {
pagenum--;
getPastes();
}
});
document.getElementById('next-page').addEventListener('click', function () {
pagenum++;
getPastes();
});
document.addEventListener('DOMContentLoaded', () => {
var mobile = window.mobileCheck();
@@ -51,6 +111,8 @@
document.querySelector('.nav-div').style.display = 'none';
document.querySelector('.nav-hamburger-menu').style.display = 'flex';
}
authenticate();
getPastes();
});
document.getElementById("hamburger-button").addEventListener("click", function () {
+7 -6
View File
@@ -84,11 +84,10 @@
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
if (result.pasteId != null) {
window.location.href = `/${result.pasteId}`;
} else if (result.error != null) {
notification(result.error);
if (obj.pasteId != null) {
window.location.href = `/${obj.pasteId}`;
} else if (obj.error != null) {
notification(obj.error);
}
})
});
@@ -309,6 +308,8 @@
border: #2a2a2a00 2px solid;
cursor: pointer;
font-size: 1.2em;
font-family: "Noto Sans Mono", "Consolas", "SF Mono", monospace;
font-weight: bold;
}
.button:hover {
@@ -319,7 +320,7 @@
.nav-div {
top: 0;
margin-top: 10px;
margin-top: 1.5px;
position: absolute;
display: flex;
flex-direction: row;
+1 -1
View File
@@ -63,7 +63,7 @@
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
isLoggingIn = true;
if (result.message != null) {
window.location.href = "/";
+9 -7
View File
@@ -67,8 +67,8 @@
const date = new Date(unixTimestamp * 1000);
return date.toLocaleString();
}
function authenticated() {
fetch('/api/accounts/authenticated')
function authenticate() {
fetch('/api/accounts/authenticate')
.then(response => response.json())
.then(data => {
if (data.message == "Authenticated") {
@@ -92,11 +92,12 @@
.then(response => response.json())
.then(json => {
info = json;
title = json.title.length > 40 ? json.title.substring(0, 40) + '...' : json.title;
document.getElementById('uploader-username').innerText = json.uploader || 'Anonymous';
document.getElementById('creationdate').innerText = localizeDateTime(json.date);
document.getElementById('paste-size').innerText = json.size;
document.getElementById('paste-size').title = `Compressed Size: ${json.compressedSize}`;
document.getElementById('paste-title').innerText = json.title;
document.getElementById('paste-title').innerText = title;
document.getElementById('paste-title').title = json.title;
if (json.title == "") {
document.getElementById('paste-title').innerText = `Untitled ${json.uid}`;
@@ -126,7 +127,7 @@
document.addEventListener("DOMContentLoaded", function () {
fetchInfo();
authenticated();
authenticate();
const creationdateElement = document.getElementById('creationdate');
const creationdateText = creationdateElement.innerText.trim();
const textElement = document.getElementById('text');
@@ -197,7 +198,7 @@
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
createNotification(`Success: ${result.message}`);
setTimeout(() => {
@@ -265,7 +266,7 @@
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
const inputWrapper = document.getElementById('input-wrapper');
inputWrapper.style.display = 'none';
@@ -313,7 +314,7 @@
width: 100%;
height: 100%;
color: white;
backdrop-filter: blur(2.5px);
backdrop-filter: blur(5px);
}
.input-wrapper-container{
z-index: 101;
@@ -325,6 +326,7 @@
border-radius: 5px;
padding: 20px;
background-color: #181818;
border: #222222 2px solid;
}
body {
+10 -17
View File
@@ -33,7 +33,7 @@
</div>
<div class="container-wrapper">
<div class="paste-container">
<h1 id="paste-title" title="{pastetitleattribute}">{pastetitle}</h1>
<h1 id="paste-title"></h1>
<h3 class="uploader-text"><a id="uploader-username" class="user-a"></a> <a id="creationdate"></a> <a id="paste-size"></a>
</h3>
<div class="paste-wrapper">
@@ -74,8 +74,8 @@
<script>
info = "";
editing = false;
function authenticated() {
fetch('/api/accounts/authenticated')
function authenticate() {
fetch('/api/accounts/authenticate')
.then(response => response.json())
.then(data => {
if (data.message == "Authenticated") {
@@ -97,8 +97,7 @@
function fetchInfo() {
fetch('/api/pastes/info?id={pasteid}')
.then(response => response.json())
.then(data => {
const json = JSON.parse(data);
.then(json => {
info = json;
document.getElementById('uploader-username').innerText = json.uploader;
document.getElementById('creationdate').innerText = localizeDateTime(json.date);
@@ -144,8 +143,7 @@
})
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
.then(result => {
if (result.content != null) {
const textElement = document.getElementById('text');
textElement.innerText = result.content;
@@ -166,10 +164,6 @@
document.addEventListener("DOMContentLoaded", function () {
fetchInfo();
authenticated();
const creationdateElement = document.getElementById('creationdate');
const creationdateText = creationdateElement.innerText.trim();
creationdateElement.innerText = localizeDateTime(parseInt(creationdateText));
var mobile = window.mobileCheck();
if (mobile) {
document.querySelector('.nav-div').style.display = 'none';
@@ -218,8 +212,7 @@
})
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
.then(result => {
if (result.message != null) {
createNotification(`Success: ${result.message}`);
setTimeout(() => {
@@ -244,8 +237,7 @@
})
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
.then(result => {
if (result.message != null) {
createNotification(`Success: ${result.message}`);
document.getElementById('text').innerText = text;
@@ -313,7 +305,7 @@
width: 100%;
height: 100%;
color: white;
backdrop-filter: blur(2.5px);
backdrop-filter: blur(5px);
}
.input-wrapper-container {
@@ -326,6 +318,7 @@
border-radius: 5px;
padding: 20px;
background-color: #181818;
border: #222222 2px solid;
}
.container-wrapper {
@@ -474,7 +467,7 @@
font-weight: 600;
}
.user-a {
.user-a:any-link {
color: rgb(190, 190, 190);
text-decoration: none;
text-decoration: underline;
+1 -1
View File
@@ -65,7 +65,7 @@
})
.then(response => response.json())
.then(obj => {
const result = JSON.parse(obj);
const result = obj;
if (result.message != null) {
window.location.href = "/";
isLoggingIn = false;
+7
View File
@@ -1,3 +1,5 @@
# Sharpbin is currently being re-written.
Quite frankly the current code base is quite messy, I also am just bored and would like to improve this since it's a pretty fun thing to make.
# Sharpbin
Sharpbin is a Pastebin type website completely in C#, except for the frontend, being pure HTML & CSS.
Sharpbin can be used for sharing large amounts of text.
@@ -13,8 +15,13 @@ Sharpbin can be used for sharing large amounts of text.
- Private encrypted pastes, sadly the encryption is server side, although client side may be soon!
- Mobile Support
- Captchas for logins and sign ups
- Editable pastes
... And more to come!
# TODO
- ~~Fix css on the confirmations~~
- ~~Update file size when an edit is made in the database~~
# Demo Website & Screenshots
You can find the test website at https://bin.whoswhip.top , there is no removed functionality and is the exact same code in this repo.
<div>
View File