# Mixing troubles

**URL:** <https://www.ruby-forum.com/t/mixing-troubles/79589>\
**Category:** Engines\
**Created:** [December 16, 2006, 9:08pm UTC](https://www.ruby-forum.com/t/mixing-troubles/79589 "2006-12-16T21:08:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![idrifter](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/e495f1/32.png) [@idrifter](https://www.ruby-forum.com/u/idrifter)\
**Post date:** [December 16, 2006, 9:08pm UTC](https://www.ruby-forum.com/t/mixing-troubles/79589/1 "2006-12-16T21:08:24Z")

</div>

Hello all. I’m having some trouble trying to wrap my brain around an  
issue I’m having with an authentication engine I’m developing. I’m  
trying to separate out my User model’s functionality into a module so  
that I can customize the user model in each rails application without  
directly modifying the engine source. I’ve been using the LoginEngine  
as a blueprint for how to do this.

The problem is that I can’t seem to set my class methods to being  
protected or they won’t be accessible from my instance methods. When I  
call change\_password on a user it throws an error that try\_credentials  
is protected. I’ve trimmed down the code to the parts that I think are  
relevant. Anyone know why this doesn’t work, or if there is a different  
way this should be done?

module AuthenticationEngine  
module AuthUser  
def self.included(base)  
base.class\_eval {  
# attr, validation stuff, etc.  
}  
base.extend(ClassMethods)  
end  
end

module ClassMethods  
protected  
def try\_credentials(login\_name, password)  
# try login  
end

```
public
  # these work ok

```

end

# instance methods

def change\_password(current, changed)  
acct = self.class.try\_credentials(read\_attribute(‘login\_name’),  
current)  
# do other stuff  
end  
end

class User \< ActiveRecord::Base  
include AuthenticationEngine::AuthUser  
end
