Created
May 15, 2024 16:46
-
-
Save Osb0rn3/8fa37f17a1892653b626b53c08bfdbbc to your computer and use it in GitHub Desktop.
Is there a way to get the admin password?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sinatra' | |
require 'mysql2' | |
require 'active_record' | |
configure { set :environment, :production } | |
ActiveRecord::Base.establish_connection( | |
adapter: 'mysql2', | |
host: ENV['DB_HOST'], | |
username: ENV['DB_USER'], | |
password: ENV['DB_PASS'], | |
database: ENV['DB_NAME'] | |
) | |
unless ActiveRecord::Base.connection.table_exists?(:users) | |
ActiveRecord::Base.connection.create_table :users, id: false do |t| | |
t.primary_key :user_id, auto_increment: true | |
t.string :email | |
t.string :password | |
end | |
ActiveRecord::Base.connection.add_index :users, :email, unique: true | |
ActiveRecord::Base.connection.execute("INSERT INTO users (email, password) VALUES ('[email protected]', '#{ENV['ADMIN_PASSWORD']}')") | |
end | |
get '/user' do | |
user_id = params[:user_id] | |
if user_id.match?(/^\d+$/) | |
user_result = ActiveRecord::Base.connection.execute("SELECT * FROM users WHERE user_id = #{user_id}").first | |
user_result ? "#{user_result[1]} (ID: #{user_result[0]})" : "User not found" | |
else | |
"Invalid user ID format" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment