Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions vlib/veb/auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

## Usage

```v

Check failure on line 12 in vlib/veb/auth/README.md

View workflow job for this annotation

GitHub Actions / check-markdown

example is not formatted

Check failure on line 12 in vlib/veb/auth/README.md

View workflow job for this annotation

GitHub Actions / check-markdown

example failed to compile
import veb
import db.pg
import veb.auth
Expand All @@ -36,6 +36,7 @@
}

fn main() {

Comment thread
spytheman marked this conversation as resolved.
Outdated
mut app := &App{
db: pg.connect(host: 'localhost', user: 'postgres', password: '', dbname: 'postgres')!
}
Expand All @@ -51,17 +52,14 @@
password_hash: auth.hash_password_with_salt(password, salt)
salt: salt
}
sql app.db {
user_id := sql app.db {
insert new_user into User
} or {}

// Get new user ID (until RETURNING is supported by ORM)
if x := app.find_user_by_name(name) {
// Generate and insert the token using user ID
token := app.auth.add_token(x.id) or { '' }
// Authenticate the user by adding the token to the cookies
ctx.set_cookie(name: 'token', value: token)
}
}!

// Generate and insert the token using user ID
token := app.auth.add_token(user_id) or { '' }
// Authenticate the user by adding the token to the cookies
ctx.set_cookie(name: 'token', value: token)

return ctx.redirect('/')
}
Expand Down Expand Up @@ -97,4 +95,4 @@
algorithm and multiple iterations.

See also:
- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)
- [OWASP Password Storage Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html)
Loading