83 lines
1.9 KiB
Bash
83 lines
1.9 KiB
Bash
|
|
#!/bin/bash
|
||
|
|
|
||
|
|
# Direct MongoDB Password Reset
|
||
|
|
# This bypasses the web interface and sets password directly
|
||
|
|
|
||
|
|
ADMIN_EMAIL="admin@skyartshop.com"
|
||
|
|
NEW_PASSWORD="Admin123!"
|
||
|
|
|
||
|
|
echo "=========================================="
|
||
|
|
echo "Direct MongoDB Password Reset"
|
||
|
|
echo "=========================================="
|
||
|
|
echo ""
|
||
|
|
echo "Resetting password for: $ADMIN_EMAIL"
|
||
|
|
echo "New password: $NEW_PASSWORD"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
# Create a C# script to generate the correct PBKDF2 hash
|
||
|
|
cat > /tmp/hash_password.cs << 'CSHARP'
|
||
|
|
using System;
|
||
|
|
using System.Security.Cryptography;
|
||
|
|
|
||
|
|
var password = args.Length > 0 ? args[0] : "Admin123!";
|
||
|
|
|
||
|
|
using var rng = RandomNumberGenerator.Create();
|
||
|
|
var salt = new byte[16];
|
||
|
|
rng.GetBytes(salt);
|
||
|
|
|
||
|
|
using var pbkdf2 = new Rfc2898DeriveBytes(password, salt, 10000, HashAlgorithmName.SHA256);
|
||
|
|
var hash = pbkdf2.GetBytes(32);
|
||
|
|
|
||
|
|
var hashBytes = new byte[48];
|
||
|
|
Array.Copy(salt, 0, hashBytes, 0, 16);
|
||
|
|
Array.Copy(hash, 0, hashBytes, 16, 32);
|
||
|
|
|
||
|
|
Console.WriteLine(Convert.ToBase64String(hashBytes));
|
||
|
|
CSHARP
|
||
|
|
|
||
|
|
# Generate the hash
|
||
|
|
HASH=$(dotnet script /tmp/hash_password.cs "$NEW_PASSWORD" 2>/dev/null)
|
||
|
|
|
||
|
|
if [ -z "$HASH" ]; then
|
||
|
|
echo "✗ Failed to generate password hash"
|
||
|
|
exit 1
|
||
|
|
fi
|
||
|
|
|
||
|
|
echo "Generated hash: ${HASH:0:40}..."
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
# Update MongoDB
|
||
|
|
mongosh --quiet SkyArtShopDB <<EOF
|
||
|
|
var result = db.AdminUsers.updateOne(
|
||
|
|
{ Email: '$ADMIN_EMAIL' },
|
||
|
|
{
|
||
|
|
\$set: {
|
||
|
|
PasswordHash: '$HASH',
|
||
|
|
LastLogin: new Date()
|
||
|
|
}
|
||
|
|
}
|
||
|
|
);
|
||
|
|
|
||
|
|
if (result.modifiedCount > 0) {
|
||
|
|
print('✓ Password updated successfully');
|
||
|
|
} else {
|
||
|
|
print('✗ Failed to update password');
|
||
|
|
}
|
||
|
|
EOF
|
||
|
|
|
||
|
|
echo ""
|
||
|
|
echo "=========================================="
|
||
|
|
echo "✓ Password Reset Complete!"
|
||
|
|
echo "=========================================="
|
||
|
|
echo ""
|
||
|
|
echo "Login credentials:"
|
||
|
|
echo " Email: $ADMIN_EMAIL"
|
||
|
|
echo " Password: $NEW_PASSWORD"
|
||
|
|
echo ""
|
||
|
|
echo "Test login:"
|
||
|
|
echo " https://skyarts.ddns.net/admin/login"
|
||
|
|
echo ""
|
||
|
|
|
||
|
|
# Clean up
|
||
|
|
rm -f /tmp/hash_password.cs
|