Thats my first idea. Maybe that gives you a little idea how to. There are a few other ways, for sure.
Save the Data somewhere (inside a database)
https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet
Encrypt, decrypt using Rails
so now the u can set the password in save way User.password = "plaintext"
and also you can receive it with User.password
class User
# password field is called "crypted_password"
def password= val
self.crypted_password =
ActiveSupport::MessageEncryptor.new(Rails.configuration.secret_key_base).encrypt_and_sign(val)
end
def password
ActiveSupport::MessageEncryptor.new(Rails.configuration.secret_key_base).decrypt_and_verify(self.crypted_password)
end
end
user = User.find(1337)
mysql = DatabaseConnection.new user.host, user.username, user.password
result = mysql.get_users(50)
raise result.inspect
use the gem mysql2
for accessing mysql-databases
https://github.com/brianmario/mysql2
create a DatabaseWrapper to connecto to users Database
class DatabaseConnection
def initialize host, username, password
@@connection = Mysql2::Client.new host: host, username: username, password: password
end
end
def run statement
@@connection.query statement
end
def get_users limit=100
run "select * from users where flag=true limit #{limit}"
end
end