Hi sorry, I'm a noob and my first language is not English.. I just started with ruby/rails 2 weeks a go, and this is the first time I am working with my mysql db.
I have a mysql database were I store all the postfix/courier-imap,etc authentication's for this we use the mysql function encrypt()
the problem is that I am making a front end on rails, and I have everything ready but when I enter the password field on the form created by rails, it will not encrypted of course because is not using the encrypt mysql function.. my question is..
1. mysql/unix encrypt on rails/ruby? is String#crypt <http://corelib.rubyonrails.org/classes/String.html#M001529> ?
2. I used ./script/generate scaffold users users so I can edit the files but were I should look to just modify one entry of the form? the password field, I need for the form to enter the data on encrypt form into the mysql database so postfix/courier can read it.
3. can I just pass a sql statement? if so how do I tell rails that everything like it is is ok but just this part of the form needs to be passed to encrypt before it writes it to the database?
better of all I been looking and Google for long before coming to ask the stupid questions here but all I can find is examples with SHA1
and yes I know encrypt is not good but for the use and compatibility with my mail I must use it.
This is probably the first part of the problem. It tends to mess with
the accessor methods that rails generates for attributes.
def crypt=\(pw\)
@crypt = pw
salt = \[Array\.new\(6\)\{rand\(256\)\.chr\}\.join\]\.pack\("m"\)\.chomp \# 2^48
combos
self.crypt = User.crypt.crypt(salt)
end
This is your second method - Your crypt= method is calling itself.
Your probably want to write self.write_attribute(:crypt,
pw.crypt(salt)). But then again you haven't said what exactly isn't
working so I'm only guessing.
Hi, thanks the response I was starting to feel helpless
attr_reader :crypt
This is probably the first part of the problem. It tends to mess with
the accessor methods that rails generates for attributes.
hmm, the only reason I used attr_readed is because is the only way I
found to
"steal" the content of the form(that ROR created based on the info my my
database using scaffold :users )
I have not found a better way yet(but I am a noob so no surprise) is
there a better way to gain control of the form?
and this will respond your question below.
my intention is so the password field will write to my mysql database
with the unix encrypt since that is how postifx and the other non RoR
applications will read it.. if not I will have use SHA1 that seens like
it have lot of examples already.
like I mention in my other email, I told RoR about my mysql database, he
created a schema and that looks ok..
then with the scafford: I was very impresed how fast RoR will create
forms around my DB content.. that is good.. the down side is
that how do I gain back "posesion" of at least the crypt column content
so RoR will encrypted before it writes it to the DB..
that was my first question I found attr_reader so far. the other part is
to use a unix encrypt to do so. and found
.crypt(salt) so far googling around.
so so far I can't write to the DB encrypted thats my problem.
Thanks and hope people can chip in their two cents.
This looks like it does the trick! thanks so much. even do I will like
if you can point me to a good doc about the problem I was having since I
really found things related but nothing really like I had, I don't just
want to copy and paste and play with it I will like to understand why I
had it wrong and why this works.