Verify root password

I have a panel written on Sinatra, linux.
Administrator must provide root password on login page.
How I can perform verification process: how to verify system password in
linux with ruby?

Fomistoklus Fomistoklus wrote in post #1178803:

Administrator must provide root password on login page.
You can use PTY and run login command :

  • PTY create a pseudo terminal,
  • login or su command can be run in this terminal

===
require ‘pty’
require ‘expect’

PTY.spawn(“su root ls”) { |read,write,pid|
read.expect(/Password:/i) { write.puts “1234” }
read.expect(/Authentication failure/) { puts “nok” }
read.each {|t| puts t }
}

Hello d’Aubarede and thank you for the method you have provided.
I’ve solved the problem by the following way:
%x(echo “#{@username}:#{@password}” | chpasswd)
a bit ugly but workable.
thank you!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs