Skip to content

Instantly share code, notes, and snippets.

View peiyush13's full-sized avatar

piyush wani peiyush13

  • Amura Marketing Technology
  • PICT pune
View GitHub Profile
@peiyush13
peiyush13 / minesweeper.rb
Created October 14, 2020 16:58
Minesweeper Board Creation
#!/bin/ruby
require 'json'
require 'stringio'
#class here
class MineBoard
attr_accessor :height, :width, :num_mines, :board
@peiyush13
peiyush13 / changes_in_login_form.html.erb
Last active November 13, 2022 11:32
Client Side Encryption in Rails
<div class="input-container">
<%= f.password_field :password, placeholder: "Password", tabindex: "2", required: "required", data: { encrypt: true } %>
</div>
<div class="hidden" id="public_key" data-value= "<%= sanitize @public_key %>"></div>
@peiyush13
peiyush13 / encrypt.js
Created September 5, 2019 20:01
client side encryption upon form submission
$(document).ready(function(){
$('form').submit(function( event ) {
var encrypt = new JSEncrypt();
$('[data-encrypt]').each(function(){
var unencrypted = $(this);
encrypt.setKey($('#public_key').attr('data-value'));
var encrypted = encrypt.encrypt(unencrypted.val());
if(encrypted) {
unencrypted.val(encrypted);
}
@peiyush13
peiyush13 / sessions_controller.rb
Last active September 5, 2019 19:50
Using RSA encryptor for Api cycle (eg. Sessions Controller)
class Users::SessionsController < Devise::SessionsController
include SessionsHelper
before_filter :generate_rsa_key, only: [:new]
prepend_before_filter -> { authenticate_encryptor([:password]) }, only: [:create]
def create
# your own code
super
end
@peiyush13
peiyush13 / session_helper.rb
Created September 5, 2019 19:36
Helper for encryption/decryption API cycle (Sessions for this case)
require 'rsa_encryptor'
# Module SessionsHelper provides public key encryption/decryption for password
#
# @author Peiyush13 <piyushwww13@gmail.com>
#
module SessionsHelper
# initializes public key used for password encryption
#
def generate_rsa_key
@peiyush13
peiyush13 / rsa_encryptor.rb
Created September 5, 2019 19:21
RSA Encryptor wrapper over OpenSSL ruby
# Class RsaEncryptor provides Public Encryption/Decryption for the data
#
# @author Peiyush13 <piyushwww13@gmail.com>
#
class RsaEncryptor
attr_reader :rsa_key, :public_key
def initialize
@rsa_key = OpenSSL::PKey::RSA.generate(1024)
@public_key = @rsa_key.public_key.to_s
@peiyush13
peiyush13 / banking_system_.idea_compiler.xml
Created October 23, 2016 21:17
its a simple banking system cmd application
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<resourceExtensions />
<wildcardResourcePatterns>
<entry name="!?*.java" />
<entry name="!?*.form" />
<entry name="!?*.class" />
<entry name="!?*.groovy" />
<entry name="!?*.scala" />