Guest User

Untitled

a guest
Sep 12th, 2018
857
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (ns sql.users.password
  2.   (:use [korma.core])
  3.   (:require [cemerick.friend :as friend]
  4.             (cemerick.friend [workflows :as workflows]
  5.                              [credentials :as creds])))
  6.  
  7. (defentity passwords
  8.   (pk :id) ;; By default "id"
  9.   (table :passwords) ;; By default the name of the symbol
  10.   (entity-fields :pw_user_id :pw_hash) ;; Default fields for selects
  11.   (database mybg) ;; if none is specified the last defdb
  12.                   ;; will be used
  13.   )
  14.  
  15. (defn add [userid passwort]
  16.   (let (hash (creds/hash-bcrypt passwort))
  17.     (sql/with-connection mysql-db
  18.        (sql/insert-records :passwords
  19.                            {:pw_user_id userid
  20.                             :pw_hash hash}))))
  21.  
  22. (defn change [userid passwort]
  23.   (let (hash (creds/hash-bcrypt passwort))
  24.     (sql/with-connection mysql-db
  25.       (sql/update-values :passwords
  26.                          [(str "pw_user_id = " userid)]
  27.                          {:pw_hash hash}))))
Add Comment
Please, Sign In to add comment