Posted in BCrypt: Can't validate passwords
Just got an answer to this from stackoverflow. I need to have both 'password' and 'password_digest' in my columns of the DB table. and I should only use the password, the password_digest is left alone (at least for this small scenario)
Posted in BCrypt: Can't validate passwords
I can't seem to get BCrypt to validate my passwords.
I'm trying to get back into rails with 7.
Can't seem to get passed password validation for my Admin:
As I understand it. It's a very straight forward process:
- Create and run db:migration Admin that has 'username', email & password_digest. All set to be strings.
- Uncomment BCrypt in the gemfile,
- run 'bundle install'
- in the Model file add 'has_secure_password'
- open rails console and create a new Admin. So far so good. I can see that the password is [Filtered] so I presume we're all good. However when I try to validate the password I always get the same error.
michael@LAPTOP-9C2OU27A:~/projects/rails/mctie$ rails c
Loading development environment (Rails 22.214.171.124)
irb(main):001:0> admin = Admin.new(username: 'screenbeam', email: 'email@example.com', password_digest: 'password')
TRANSACTION (0.3ms) BEGIN
Admin Exists? (0.7ms) SELECT 1 AS one FROM "admins" WHERE LOWER("admins"."username") = LOWER($1) LIMIT $2 [["username", "screenbeam"], ["LIMIT", 1]]
Admin Create (0.5ms) INSERT INTO "admins" ("username", "email", "password_digest", "created_at", "updated_at") VALUES ($1, $2, $3, $4, $5) RETURNING "id" [["username", "screenbeam"], ["email", "firstname.lastname@example.org"], ["password_digest", "[FILTERED]"], ["created_at", "2022-03-25 10:54:35.072350"], ["updated_at", "2022-03-25 10:54:35.072350"]]
TRANSACTION (9.8ms) COMMIT
/home/michael/.rbenv/versions/3.0.3/lib/ruby/gems/3.0.0/gems/bcrypt-3.1.17/lib/bcrypt/password.rb:60:in `initialize': invalid hash (BCrypt::Errors::InvalidHash)
Am I missing something very basic, what does it take for me to send a simple email with 'hello' to my personal inbox in ruby (or Rails)
in php it's this simple : mail("email@example.com","My subject",$msg);
I know php has to be running from a server to able to do anything, but what would I need to get the equivalent in ruby (or rails?) from my local computer?
I tried the Rails Guides Action mailer basics only to be rewarded with output in the terminal :(
...or copy and paste the following from https://www.tutorialspoint.com/ruby/ruby_sending_email.htm
with the following code running in a test_email.rb file and execute with $ruby test_email.rb
message = <
From: Private Person
To: A Test User
Subject: SMTP e-mail test
This is a test e-mail message.
Net::SMTP.start('localhost') do |smtp|
smtp.send_message message, 'firstname.lastname@example.org', 'email@example.com'
Returns this :
/Users/me/.rbenv/versions/2.7.2/lib/ruby/2.7.0/net/smtp.rb:539:in `initialize': Connection refused - connect(2) for "localhost" port 25 (Errno::ECONNREFUSED)
(Can that only run from a server?)
I started learning ruby & rails back in 2016. Built a fairly decent project as a self-learning project. Got busy with other stuff and didn't touch ruby or rails until this December. Got some basic tutorial projects going, but was curious on upgrading my old project that was built with Rails 4.2.4 (Ruby 2.3.0).
I would like to bring it up to Rails 126.96.36.199 as all my other tutorial & learning projects are using that version.
One part of the challenge would be to force me to start writing Mini Tests as that would be a life saver when it comes to checking if the app still works at current newly upgraded version and/or where it breaks.
Should I upgrade step by step?
from 4.2.4 to last 4.x.x version (188.8.131.52), then 184.108.40.206, then 220.127.116.11?
Or should I just go from 4.2.4 to 18.104.22.168 directly?
Posted in RSpec w/capybara vs Mini Test
Can anybody recommend any good tutorials/books/videos with Mini Test that are meant for beginners to rails (and ruby)?
I personally prefer videos, but mini test seem to be such a rarity I'll take anything I can get.
Beginner, playing around with Rails 6.0.
I would like to allow the admin of a Rails site to change the site for all anonymous users who come to it:
-how many articles per page while using pagination
-color scheme (primary & secondary colors)
-additional navigation links that are static/absolute.
-landing page greeting text and default background image.
-contact email and pre-filled in content in that email link.
I know this can be created and saved in the database, but is it not wasteful of requesting the DB for every page to send request for all examples above, when they will most likely remain the same for long stretches of time, but still allows the admin to update the image once per season, and maybe update the greetings text twice a year, change contact email once per 3 years, etc...
Note: the DB would still be used for the typical, article CRUD's
Is there a built in hash that's a part of the rail framework, not the db, that the views or controllers can access and also be updated by the logged-in admin? If not, would it be possible to add one?
If it's possible, but a bad idea, why? (security hole?)
Is this what writing rails as an api app is more suitable for?
Am I just a beginner who's trying to lookout for wasted resources that in the real world comes down to minimal waste/requests that is fully normal and expected?
Thanks in advance for any learning on why this is bad/smart/dumb/possible/impossible within the Rails framework.
Posted in Is there a beginners course?
As a current beginner/student of rails I'll suggest my current (and 2nd attempt) at Rails:
I Find that most (not all) courses tries to jam in as much Ruby in in an often too short or too intensive block to get to Rails faster.
To avoid that I got a Ruby only course and a course that focuses on Rails.
I am a big fan of video tutorials so I if that's your preferred style I got at udemy (I always buy when they run discounts)
for rails : https://www.udemy.com/course/the-complete-ruby-on-rails-developer-course/
for ruby : https://www.udemy.com/course/learn-to-code-with-ruby-lang/
I discovered that I also need to learn Web packer, and I got some courses on that, but I haven't had a chance to start them, and I'm not 100% sure they are good, so I'll keep quiet on that end until I have started on any of them.
However, I would say that I've only heard good stuff about the Odin project, and Hartl's a great author, so if that learning style is more your jam, follow Red's links.