I have coded an Laravel 2FA PGP login using GPGME. I am sure I have installed GPGME correct!
After a User signs in, he gets a Message generated with PGP from his Public Key that he saved before.
But I just get always an empty field with no generated Key.
My Controller:
public function showDecryptionForm()
{
if(session()->has('user_name'))
{
$user_name = session()->get('user_name');
$user_password = session()->get('user_password');
}
else
{
return redirect()->route('login');
}
$user_details = User::where('username',$user_name)->first();
$secret = $this->generateSecretKey();
$secret_hash = password_hash($secret, PASSWORD_BCRYPT);
$this->secret_code = $secret_hash;
//echo $user_details->pgp;
putenv("GNUPGHOME =/home/.gnupg");
$gpg = new gnupg();
$key = $gpg->import($user_details->pgp);
$gpg->addencryptkey($key['fingerprint']);
$enc = $gpg->encrypt($secret);
$gpg->clearencryptkeys();
//echo '<textarea rows="30" class="form-control" name="pgp-msg">'.$enc.'</textarea>';
session()->flash('secret_hash',$secret_hash);
return view('auth.decryptionform',compact('enc','user_name','user_password'));
}
public function postDecryptionForm(Request $request)
{
if (Hash::check($request->decrypt_code,session()->get('secret_hash')))
{
if (Auth::attempt(['username' => $request->user_name, 'password' => $request->user_password]))
{
$user = Auth::user();
$user->last_seen = date('Y-m-d H:i:s', time());
$user->save();
return redirect()->route('home');
}
}
else
{
session()->flash('errormessage','Your PGP Decryption Code is Wrong!!!');
return redirect('login');
}
}
public function generateSecretKey($length = 15)
{
$secret = '';
for($i = 0; $length > $i; $i++)
{
$secret = $secret.rand(0,9);
}
return $secret;
}
}
Blade:
<label for="message">Public Key:</label>
<textarea name="message" id="message" class="form-control" rows="15" cols="40" readonly></textarea>
</div>
<div class="form-group">
<label for="decrypt_code">Please Enter the Message:</label>
<input type="text" name="decrypt_code" id="decrypt_code" class="form-control">
Have I forgotten something to print
the code in my script?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire