This file contains 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
# @param {String} s | |
# @param {String} t | |
# @return {Boolean} | |
# def is_subsequence(s, t) | |
# i = 0 | |
# t.each_char do |c| | |
# i += 1 if c == s[i] | |
# end | |
# i == s.length | |
# end |
This file contains 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
# @param {Character[][]} board | |
# @param {Integer[]} click | |
# @return {Character[][]} | |
# def update_board(board, click) | |
# y = click[0] | |
# x = click[1] | |
# total_x = board[0].length | |
# total_y = board.length | |
# board[y][x] = 'X' if board[y][x] == 'M' |
This file contains 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
def serialize_into_session(record) | |
[record.to_key, record.authenticatable_salt] | |
end |
This file contains 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
def authenticatable_salt | |
encrypted_password[0,29] if encrypted_password | |
end |
This file contains 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
def serialize_from_session(key, salt) | |
record = to_adapter.get(key) | |
record if record && record.authenticatable_salt == salt | |
end |
This file contains 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
class User < ApplicationRecord | |
devise :database_authenticatable, :recoverable, :rememberable | |
def authenticatable_salt | |
return super unless session_token | |
"#{super}#{session_token}" | |
end |
This file contains 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
class RegistrationsController < ApplicationController | |
def create | |
user = User.new(username: params[:registration][:username]) | |
create_options = WebAuthn::Credential.options_for_create( | |
user: { | |
name: params[:registration][:username], | |
id: user.webauthn_id | |
} | |
) |
This file contains 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
{ | |
"challenge": "Wj4vWoL1BeG0PB8iJTKMfvLH8rBt3CA6PfM4QBIyKmU", | |
"timeout": 120000, | |
"rp": { "name": "WebAuthn Rails Demo App" }, | |
"user": { | |
"name": "truongnmt", | |
"id": "OXtCbb6VcBaLFC5GBOjIfpKYCMxJom04VPw9c-WRvhJ5uAHWhBkQZk_-0NGOmNnK4Yx2G5Pw9nyLLRKZkkCndA", | |
"displayName": "truong" | |
}, | |
"pubKeyCredParams": [ |
This file contains 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
create(event) { | |
var [data, status, xhr] = event.detail; | |
console.log(data); | |
var credentialOptions = data; | |
// Registration | |
if (credentialOptions["user"]) { | |
var credential_nickname = event.target.querySelector("input[name='registration[nickname]']").value; | |
var callback_url = `/registration/callback?credential_nickname=${credential_nickname}` |
This file contains 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
function create(callbackUrl, credentialOptions) { | |
WebAuthnJSON.create({ "publicKey": credentialOptions }).then(function(credential) { | |
callback(callbackUrl, credential); | |
}).catch(function(error) { | |
showMessage(error); | |
}); | |
console.log("Creating new public key credential..."); | |
} |