martice.nicks
martice.nicks

Reputation: 21

How do I validate a password typed into a scala.swing.passwordfield?

I am currently working on a login system for an application using scala 2.9.1. My question is how do I validate a password that is entered into a passwordfield since the returned string is encrypted. I would think there is a simple .command for password matching? Thank you for the assistance!

Upvotes: 1

Views: 265

Answers (1)

ziggystar
ziggystar

Reputation: 28686

Use the method password to obtain the entered text and do whatever you like. I don't think there is any encryption.

What might be notable is that password returns an array of Char and not a String. You can use password.mkString to turn it into a String.

scala> import swing._
import swing._

scala> val frame = new MainFrame
MainFrame   

scala> val frame = new MainFrame
frame: scala.swing.MainFrame <snip>

scala> val pwf = new PasswordField
pwf: scala.swing.PasswordField = <snip>

scala> frame.contents = pwf
frame.contents: Seq[scala.swing.Component] = <snip>

scala> frame.open

scala> pwf.password
res1: Array[Char] = Array(a, b, c, d, e, f)

Upvotes: 3

Related Questions