标签: password-confirmation

验证器,密码确认

我无法弄清楚为什么模型不会检查密码确认,这是模型的代码:

class User < ActiveRecord::Base
  attr_accessor :password_confirmation
  validates :email, :presence =>true,
                    :uniqueness=>true
  validates :password, :presence =>true,
                    :length => { :minimum => 5, :maximum => 40 },
                    :confirmation =>true
  validates_confirmation_of :password
end
Run Code Online (Sandbox Code Playgroud)

控制器用于从视图中获取数据并尝试执行保存,这是视图的代码:

<h1>Registration process</h1>
<%= form_for(@new_user) do |f|%>
<% if @new_user.errors.any? %>
  <div id="errorExplanation">
    <h2><%= pluralize(@new_user.errors.count, "error") %> prohibited this article from being saved:</h2>
    <ul>
    <% @new_user.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
  <% end %>
    <%= f.label :email %><br />
    <%= f.text_field :email %><br …
Run Code Online (Sandbox Code Playgroud)

validation password-confirmation ruby-on-rails-3

18
推荐指数
1
解决办法
2万
查看次数

Django modelform如何添加确认密码字段?

在这里,我需要confirmation password在我的表单中添加一个额外的.我使用了Django的模型.我还需要验证两个密码.如果,它必须引发验证错误password1 != password2.

这是我的forms.py:

class UserForm(forms.ModelForm):
    password=forms.CharField(widget=forms.PasswordInput())

    class Meta:
        model=User
        fields=('username','email','password')

class UserProfileForm(forms.ModelForm):
    YESNO_CHOICES = (('male', 'male'), ('female', 'female'))
    sex = forms.TypedChoiceField(choices=YESNO_CHOICES, widget=forms.RadioSelect)
    FAVORITE_COLORS_CHOICES=(('red','red'),('blue','blue'))
    favorite_colors = forms.MultipleChoiceField(required=False,widget=forms.CheckboxSelectMultiple, choices=FAVORITE_COLORS_CHOICES)
    dob = forms.DateField(widget=forms.DateInput(format = '%d/%m/%Y'), 
                                 input_formats=('%d/%m/%Y',))

    class Meta:

        model=UserProfile
        fields=('phone','picture','sex','favorite_colors','dob')
Run Code Online (Sandbox Code Playgroud)

这是我的注册功能:

def register(request):
    registered = False
    if request.method == 'POST':
        user_form = UserForm(data=request.POST)
        profile_form = UserProfileForm(data=request.POST)



        if user_form.is_valid() and profile_form.is_valid():
            user = user_form.save(commit=False)
            user.set_password(user.password)
            user.save()
            profile = profile_form.save(commit=False)
            profile.user = user
            if 'picture' in request.FILES:
                profile.picture = …
Run Code Online (Sandbox Code Playgroud)

django-forms password-confirmation

16
推荐指数
2
解决办法
1万
查看次数

未定义的方法password_changed?错误

我正在尝试设置我的程序,以便仅在密码更改时验证密码(这样用户可以编辑其他信息而无需输入密码).

我目前收到错误消息

NoMethodError in UsersController#create, undefined method `password_changed?' for #<User:0x00000100d1d7a0>
Run Code Online (Sandbox Code Playgroud)

当我尝试登录时

这是我的验证码user.rb:

    validates :name,  :presence => true,
 :length   => { :maximum => 50 }
validates :email, :presence   => true,
:format     => { :with => email_regex },
:uniqueness => { :case_sensitive => false }
validates :password, :presence =>true, :confirmation => true, :length => { :within => 6..40 }, :if=>:password_changed?  
Run Code Online (Sandbox Code Playgroud)

这是我的创建方法users_controller.rb:

def create
    @user = User.new(params[:user])
    if @user.save
        sign_in @user
        flash[:success] = "Welcome to the Sample App!"
        redirect_to …
Run Code Online (Sandbox Code Playgroud)

validation ruby-on-rails password-confirmation nomethoderror

8
推荐指数
1
解决办法
2980
查看次数

rails 4密码确认ca

我正在浏览一个Rails教程,在一个关于用户验证的部分,我一直收到一个错误,告诉我在编辑/创建用户时我的密码确认不能为空.我查看了之前的答案,看起来人们使用的是attr_accessible,它被拉出铁轨.我是一个总计rails/web dev newb所以我不知道如何继续.这个观点是在HAML,对不起,如果这是不好的做法.

模型

class User < ActiveRecord::Base

  before_save { self.email = email.downcase }
  attr_accessor :name, :email
  validates_confirmation_of :password
  has_secure_password


  validates :name, presence: true, length:{ maximum: 16 }

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
    uniqueness: { case_sensitive: false }

  validates :password, length: { minimum: 6 }


  has_one :profile
  has_many :posts


  end
Run Code Online (Sandbox Code Playgroud)

视图

= form_for(@user) do |f|
  - if @user.errors.any?
    #error_explanation
      %h2
        = pluralize(@user.errors.count, "error")
        prohibited this username from being saved:
      %ul
        - @user.errors.full_messages.each do …
Run Code Online (Sandbox Code Playgroud)

ruby ruby-on-rails password-confirmation

7
推荐指数
1
解决办法
6271
查看次数

AngularJS密码确认noMatch无法正常工作?

我在这里有这个脚本:

angular.module('UserValidation', []).directive('validPasswordC', function () {
    return {
        require: 'ngModel',
        link: function (scope, elm, attrs, ctrl) {
            ctrl.$parsers.unshift(function (viewValue, $scope) {
                var noMatch = viewValue != scope.signupForm.password.$viewValue
                ctrl.$setValidity('noMatch', !noMatch)
            })
        }
    }
});    
Run Code Online (Sandbox Code Playgroud)

这是html:

<div class="fieldset" ng-class="{'has-error':formData.password.$invalid && !formData.password.$pristine}">
   <label>Password</label>
   <input type="password" id="password" name="password" ng-model="formData.password" ng-minlength="8" ng-maxlength="20" ng-pattern="/(?=.*[a-z])(?=.*[A-Z])(?=.*[^a-zA-Z])/" placeholder="password" required />

   <p ng-show="signupForm.password.$error.required" class="error">*</p>
   <p ng-show="signupForm.password.$error.minlength" class="error">
      Passwords must be between 8 and 20 characters.</p>
   <p ng-show="signupForm.password.$error.pattern" class="error">
      Must contain one lower &amp; uppercase letter, and one non-alpha character (a …
Run Code Online (Sandbox Code Playgroud)

forms validation password-confirmation angularjs

5
推荐指数
2
解决办法
3万
查看次数

我可以使用默认验证选项在引导程序4中检查密码确认吗?

我已阅读https://getbootstrap.com/docs/4.0/components/forms/#validation。阅读后,我想可以使用bootstrap 4默认选项在客户端站点中检查确认密码。而且,由于我是Web开发新手,所以我找不到解决方案。

如果有可能,那怎么办?

我的注册模式是

<li><button type="button" class="btn btn-light btn-lg" data-toggle="modal" data-target="#signUp">Sign Up</button></li>
                    <li><button type="button" class="btn btn-light btn-lg" data-toggle="modal" data-target="#signIn" style="margin-left:10px">Sign In</button></li>

                    <!-- Modal content-->




                    <div class="modal fade" id="signUp" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h5 class="modal-title" id="exampleModalLabel">Sign Up</h5>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true">&times;</span>
                                    </button>
                                </div>
                                <div class="modal-body">
                                    <form>
                                        <div class="form-group">
                                            <label for="email" class="col-form-label">Email address:</label>
                                            <input type="email" class="form-control" id="email" name="email">
                                        </div>
                                        <div class="form-group">
                                            <label for="pwd" class="col-form-label">Password:</label>
                                            <input type="password" class="form-control" id="pwd" name="password">
                                        </div> …
Run Code Online (Sandbox Code Playgroud)

password-confirmation

5
推荐指数
1
解决办法
9226
查看次数

告知AuthLogic不使用密码确认

我有这个观点:

new.html.haml

%h1 New account

- form_for @user do |f|
  = f.error_messages
  = render :partial => "form", :object => f
  = f.submit "Create account"
Run Code Online (Sandbox Code Playgroud)

_form.html.haml

= form.label :email
= form.text_field :email
%br/
= form.label :password, form.object.new_record? ? nil : "Change password"
= form.password_field :password
Run Code Online (Sandbox Code Playgroud)

导致这个邪恶的错误消息:

1错误禁止此用户被保存

以下字段存在问题:

  • 密码确认太短(最少4个字符)

我不想要密码确认.密码确认很糟糕,他们阻止超快速注册,这太棒了!任何人都可以解释我如何禁用密码确认?谢谢.

user-experience ruby-on-rails authlogic password-confirmation

4
推荐指数
1
解决办法
1760
查看次数

Rails仅在用户创建或更新时验证

validates_confirmation_of :password我的用户模型中有一个.问题是我还在@comment.user.save!创建注释时运行以更新用户帐户的某些属性.

创建评论时出错Validation failed: Password confirmation can't be blank.我无法添加:on => "save"到我的验证,因为我的comments控制器也调用了保存功能.

在创建和更新时已经阅读了这个线程Rails模型验证,但它没有回答我的具体问题.

更新 用户模型代码段:

class User < ActiveRecord::Base

  attr_accessor :password

  # validations
  validates_presence_of :username
  validates_length_of :username, :within => 6..25
  validates_uniqueness_of :username
  validates_presence_of :email
  validates_length_of :email, :maximum => 100
  validates_format_of :email, :with => EMAIL_REGEX
  validates_confirmation_of :password, :if => :password_changed?
  validates_presence_of :password_confirmation
  validates_length_of :password, :within => 4..25, :on => :create

  before_save :create_hashed_password
  after_save :clear_password

  private

  def clear_password
    self.password = …
Run Code Online (Sandbox Code Playgroud)

validation password-confirmation ruby-on-rails-3

4
推荐指数
2
解决办法
3687
查看次数

无法与主机smtp.gmail.com建立连接[Permission denied#13]

我正在使用Laravel-5.1进行开发.我有.env配置文件在开发环境上正常工作,这是Windows 8,4GB RAM.当我部署到Centos-6的远程服务器时,我开始收到此错误:

Swift_TransportException in StreamBuffer.php line 265:
Connection could not be established with host smtp.gmail.com [Permission denied #13]
in StreamBuffer.php line 265
at Swift_Transport_StreamBuffer->_establishSocketConnection() in StreamBuffer.php line 62
at Swift_Transport_StreamBuffer->initialize(array('protocol' => 'tcp', 'host' => 'smtp.gmail.com', 'port' => '587', 'timeout' => '30', 'blocking' => '1', 'tls' => true, 'type' => '1')) in AbstractSmtpTransport.php line 113
at Swift_Transport_AbstractSmtpTransport->start() in Mailer.php line 79
at Swift_Mailer->send(object(Swift_Message), array()) in Mailer.php line 395
at Mailer->sendSwiftMessage(object(Swift_Message)) in Mailer.php line 181
at Mailer->send('email.verify', array('users' => object(User), 'confirmation_code' …
Run Code Online (Sandbox Code Playgroud)

email smtp password-confirmation gmail-api laravel-5.1

4
推荐指数
1
解决办法
3317
查看次数

Javascript验证复杂密码

我正在创建一个创建帐户页面,我正在尝试验证他们创建的密码是否遵循正确的格式.密码格式必须为:最小值:15个字符2 UPPER 2 lower 2数字2特殊

我已经搜索过并且只能找到一个验证脚本来检查每个字符中的1个,我目前正在使用它.我还使用一个函数来确认密码和confrim密码字段匹配密钥,以及一个单独的功能来提交相同的功能.验证它们在提交时是否匹配也不起作用.

这是我到目前为止所拥有的:

<script>
var anUpperCase = /[A-Z]/;
var aLowerCase = /[a-z]/; 
var aNumber = /[0-9]/;
var aSpecial = /[!|@|#|$|%|^|&|*|(|)|-|_]/;

function testpasswd(form, ctrl, value)
{ 
    if (value.length < 15 || value.search(anUpperCase) == -1 ||  
        value.search (aLowerCase) == -1 || value.search (aNumber) == -1 || value.search (aSpecial) == -1)  
    { 
        document.getElementById("pw").innerHTML="Invalid Password"; 
    }  
    else 
    { 
        location.href = "submit.cfm"; 
    }  

}

function checkpasswds()   
{ 
  theForm = document.getElementById ( 'reg' ) ; 
  confm = document.getElementById ( 'confirm') ;
    if …
Run Code Online (Sandbox Code Playgroud)

javascript passwords password-checker password-confirmation

1
推荐指数
1
解决办法
9737
查看次数