I will preface this question by saying that I am completely new to the concept of password hashing... bear with me.
I have been using the odbcConnect function from the RODBC package to establish a connection to a database. To streamline my processes, I have been storing my password locally in a text file and then reading it in, passing it to the function to make the connection. My custom function for establishing the connection looks something like this:
setconnect <- function(){
db <-"myODBCname"
user <- readChar("C:\\Credentials\\username.txt",file.info("C:\\Credentials\\username.txt")$size)
pass <- readChar("C:\\Credentials\\my_password.txt", file.info("C:\\Credentials\\my_password.txt")$size)
conn <- odbcConnect(db, uid = user, pwd = pass)
return(conn)
}
I want to replace that text file with a hashed password to make it more secure.
I can hash a password using the bcrypt package's hashpw function like so:
> pass <- "myPassword"
> hash <- hashpw(pass)
> hash
[1] "$2a$12$jNtZmPwUt4pqEoTumGxK5e5MU.AgMGlygbGWyJUxMmShl7p1/VWBW"
Ideally, I would replace what is in the username.txt and my_password.txt file noted above with the result of this hashing, and modify my setconnect function to decode the hash before passing it to odbcConnect.
However, I have no idea how to go about decoding the hash... Is this possible?
It is not possible to decode a cryptographic hash, that is the point of thea hash, it is a one-way function.
One can only brute-force, that is try passwords hoping to find a matching hash, that will probably take until past the end of the Earth.
Depending on the platform there may be a secure key store to save the password.